Zelda Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2023-11-06 12:17:09
Exec Total Coverage
Lines: 1683 4298 39.2%
Functions: 132 334 39.5%
Branches: 933 3052 30.6%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro5/joystick.h"
5 #include "base/qrs.h"
6 #include "base/dmap.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <cstring>
10 #include <math.h>
11 #include <map>
12 #include <filesystem>
13 #include <ctype.h>
14 #include <sstream>
15 #include "base/zc_alleg.h"
16 #include "gamedata.h"
17 #include "zc/zc_init.h"
18 #include "init.h"
19 #include "zc/replay.h"
20 #include "zc/cheats.h"
21 #include "zc/render.h"
22 #include "base/zc_math.h"
23 #include "base/zapp.h"
24 #include "dialog/cheatkeys.h"
25 #include "metadata/metadata.h"
26 #include "zc/zelda.h"
27 #include "zc/saves.h"
28 #include "tiles.h"
29 #include "base/colors.h"
30 #include "pal.h"
31 #include "base/zsys.h"
32 #include "qst.h"
33 #include "zc/zc_sys.h"
34 #include "play_midi.h"
35 #include "gui/jwin_a5.h"
36 #include "base/jwinfsel.h"
37 #include "base/gui.h"
38 #include "midi.h"
39 #include "subscr.h"
40 #include "zc/maps.h"
41 #include "sprite.h"
42 #include "zc/guys.h"
43 #include "zc/hero.h"
44 #include "zc/title.h"
45 #include "particles.h"
46 #include "sound/zcmusic.h"
47 #include "zconsole.h"
48 #include "zc/ffscript.h"
49 #include "dialog/info.h"
50 #include "dialog/alert.h"
51 #include "zc/combos.h"
52 #include "zc/jit.h"
53 #include "zc/zc_subscr.h"
54 #include <fmt/format.h>
55 #include "zinfo.h"
56 #include "base/misctypes.h"
57
58 #ifdef __EMSCRIPTEN__
59 #include "base/emscripten_utils.h"
60 #endif
61
62 using namespace std::chrono_literals;
63
64 extern FFScript FFCore;
65 extern bool Playing;
66 int32_t sfx_voice[WAV_COUNT];
67 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
68 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
69
70 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
71 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
72
73 extern byte monochrome_console;
74
75 extern HeroClass Hero;
76 extern zcmodule moduledata;
77 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
78 extern particle_list particles;
79 extern int32_t loadlast;
80 extern char *sfx_string[WAV_COUNT];
81 byte use_dwm_flush;
82 byte use_save_indicator;
83 int32_t paused_midi_pos = 0;
84 byte midi_suspended = 0;
85 byte zc_192b163_warp_compatibility;
86 char modulepath[2048];
87 bool epilepsyFlashReduction;
88 signed char pause_in_background_menu_init = 0;
89 byte pause_in_background = 0;
90 bool is_sys_pal = false;
91 static bool load_control_called_this_frame;
92 extern PALETTE* hw_palette;
93 extern bool update_hw_pal;
94 extern const char* dmaplist(int32_t index, int32_t* list_size);
95 int32_t getnumber(const char *prompt,int32_t initialval);
96
97 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
98 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
99
100 static const char *qst_module_name = "current_module";
101 #ifdef ALLEGRO_LINUX
102 static const char *samplepath = "samplesoundset/patches.dat";
103 #endif
104 char qst_files_path[2048];
105
106 #ifdef _MSC_VER
107 #define getcwd _getcwd
108 #endif
109
110 bool rF11();
111 bool rI();
112 bool rQ();
113 bool zc_key_pressed();
114
115 #ifdef _WIN32
116
117 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
118 extern "C"
119 {
120 typedef HRESULT(WINAPI *t_DwmFlush)();
121 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
122 }
123
124 void do_DwmFlush()
125 {
126 static HMODULE shell = LoadLibrary("dwmapi.dll");
127
128 if(!shell)
129 return;
130
131 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
132 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
133
134 BOOL enabled;
135 isEnabled(&enabled);
136
137 if(isEnabled)
138 flush();
139 }
140
141 #endif // _WIN32
142
143 83751 bool flash_reduction_enabled(bool check_qr)
144 {
145
4/4
✓ Branch 0 taken 81530 times.
✓ Branch 1 taken 2221 times.
✓ Branch 2 taken 81074 times.
✓ Branch 3 taken 83295 times.
83751 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
146 }
147
148 // Dialogue largening
149 void large_dialog(DIALOG *d)
150 {
151 large_dialog(d, 1.5);
152 }
153
154 void large_dialog(DIALOG *d, float RESIZE_AMT)
155 {
156 if(!d[0].d1)
157 {
158 d[0].d1 = 1;
159 int32_t oldwidth = d[0].w;
160 int32_t oldheight = d[0].h;
161 int32_t oldx = d[0].x;
162 int32_t oldy = d[0].y;
163 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
164 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
165 d[0].w = int32_t(d[0].w*RESIZE_AMT);
166 d[0].h = int32_t(d[0].h*RESIZE_AMT);
167
168 for(int32_t i=1; d[i].proc !=NULL; i++)
169 {
170 // Place elements horizontally
171 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
172 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
173
174 if(d[i].proc != d_stringloader)
175 {
176 if(d[i].proc==d_bitmap_proc)
177 {
178 d[i].w *= 2;
179 }
180 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
181 }
182
183 // Place elements vertically
184 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
185 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
186
187 // Vertically resize elements
188 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
189 {
190 d[i].h = int32_t((double)d[i].h*1.5);
191 }
192 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
193 {
194 d[i].y += int32_t((double)d[i].h*0.25);
195 d[i].h = int32_t((double)d[i].h*1.25);
196 }
197 else if(d[i].proc==d_bitmap_proc)
198 {
199 d[i].h *= 2;
200 }
201 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
202
203 // Fix frames
204 if(d[i].proc == jwin_frame_proc)
205 {
206 d[i].x++;
207 d[i].y++;
208 d[i].w-=4;
209 d[i].h-=4;
210 }
211 }
212 }
213
214 for(int32_t i=1; d[i].proc!=NULL; i++)
215 {
216 if(d[i].proc==jwin_slider_proc)
217 continue;
218
219 // Bigger font
220 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
221
222 if(!d[i].dp2 && bigfontproc)
223 {
224 d[i].dp2 = get_zc_font(font_lfont_l);
225 }
226 else if(!bigfontproc)
227 {
228 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
229 }
230
231 // Make checkboxes work
232 if(d[i].proc == jwin_check_proc)
233 d[i].proc = jwin_checkfont_proc;
234 else if(d[i].proc == jwin_radio_proc)
235 d[i].proc = jwin_radiofont_proc;
236 }
237
238 jwin_center_dialog(d);
239 }
240
241
242 /**********************************/
243 /******** System functions ********/
244 /**********************************/
245
246 static char cfg_sect[] = "zeldadx"; //We need to rename this.
247 static char ctrl_sect[] = "Controls";
248 static char sfx_sect[] = "Volume";
249
250 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
251 {
252 return D_O_K;
253 }
254
255 bool is_reserved_key(int c)
256 {
257 switch(c)
258 {
259 case KEY_ESC:
260 return true;
261 }
262 return false;
263 }
264 bool is_reserved_keycombo(int c, int modflag)
265 {
266 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
267 return true;
268 return false;
269 }
270 bool checkcheat(Cheat cheat)
271 {
272 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
273 return true; //Main key pressed
274 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
275 return true; //Alt key pressed
276 return false;
277 }
278 117 void load_default_cheatkeys()
279 {
280 117 memset(cheatkeys, 0, sizeof(cheatkeys));
281 117 cheatkeys[Cheat::Life][0] = KEY_H;
282 117 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
283 117 cheatkeys[Cheat::Magic][0] = KEY_M;
284 117 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
285 117 cheatkeys[Cheat::Rupies][0] = KEY_R;
286 117 cheatkeys[Cheat::Bombs][0] = KEY_B;
287 117 cheatkeys[Cheat::Arrows][0] = KEY_A;
288 117 cheatkeys[Cheat::Clock][0] = KEY_I;
289 117 cheatkeys[Cheat::Walls][0] = KEY_F11;
290 117 cheatkeys[Cheat::Fast][0] = KEY_Q;
291 117 cheatkeys[Cheat::Light][0] = KEY_L;
292 117 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
293 117 cheatkeys[Cheat::Kill][0] = KEY_K;
294 117 cheatkeys[Cheat::GoTo][0] = KEY_G;
295 117 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
296 117 cheatkeys[Cheat::ShowL0][0] = KEY_0;
297 117 cheatkeys[Cheat::ShowL1][0] = KEY_1;
298 117 cheatkeys[Cheat::ShowL2][0] = KEY_2;
299 117 cheatkeys[Cheat::ShowL3][0] = KEY_3;
300 117 cheatkeys[Cheat::ShowL4][0] = KEY_4;
301 117 cheatkeys[Cheat::ShowL5][0] = KEY_5;
302 117 cheatkeys[Cheat::ShowL6][0] = KEY_6;
303 117 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
304 117 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
305 117 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
306 117 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
307 117 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
308 117 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
309 117 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
310 117 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
311 117 }
312 117 void load_game_configs()
313 {
314 117 strcpy(moduledata.module_name,zc_get_config("ZCMODULE",qst_module_name,"classic.zmod"));
315 117 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
316 117 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
317 117 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
318 117 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
319 117 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
320 117 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
321 117 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
322 117 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
323 117 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
324 117 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
325 117 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
326 117 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
327 117 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
328 117 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
329
330 //cheat modifier keya
331 117 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
332 117 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
333 117 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
334 117 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
335
336 //cheat keys
337 117 load_default_cheatkeys();
338 char buf[256];
339
2/2
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 4095 times.
4212 for(size_t q = 1; q < Cheat::Last; ++q)
340 {
341
1/2
✓ Branch 0 taken 4095 times.
✗ Branch 1 not taken.
4095 if(!bindable_cheat((Cheat)q)) continue;
342 4095 std::string cheatname = cheat_to_string((Cheat)q);
343
1/2
✓ Branch 0 taken 4095 times.
✗ Branch 1 not taken.
4095 util::lowerstr(cheatname);
344 4095 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
345
1/2
✓ Branch 0 taken 4095 times.
✗ Branch 1 not taken.
4095 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
346 4095 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
347
1/2
✓ Branch 0 taken 4095 times.
✗ Branch 1 not taken.
4095 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
348 4095 }
349
350
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
351 joystick_index = 0;
352
353 117 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
354 117 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
355 117 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
356 117 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
357 117 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
358 117 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
359 117 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
360 117 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
361 117 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
362 117 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
363
364 117 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
365 117 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
366 117 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
367 117 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
368
369 117 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
370 117 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
371 117 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
372 117 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
373 117 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
374 117 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
375 117 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
376 117 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
377 117 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
378 117 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
379 117 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
380
381 117 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
382 117 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
383 117 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
384 117 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
385
386 117 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
387
388 117 digi_volume = zc_get_config(sfx_sect,"digi",248);
389 117 midi_volume = zc_get_config(sfx_sect,"midi",255);
390 117 sfx_volume = zc_get_config(sfx_sect,"sfx",248);
391 117 emusic_volume = zc_get_config(sfx_sect,"emusic",248);
392 117 pan_style = zc_get_config(sfx_sect,"pan",1);
393 // 1 <= zcmusic_bufsz <= 128
394 117 zcmusic_bufsz = vbound(zc_get_config(sfx_sect,"zcmusic_bufsz",64),1,128);
395 117 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
396 117 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
397 117 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
398 117 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
399 117 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
400 117 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
401 117 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
402 117 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
403 #ifdef __EMSCRIPTEN__
404 if (em_is_mobile()) NameEntryMode = 2;
405 #endif
406 117 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
407 117 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
408 117 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
409 117 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
410 117 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
411
412 117 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
413 117 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
414 117 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
415 117 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
416 117 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
417 117 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
418 117 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
419
420 117 loadlast = zc_get_config(cfg_sect,"load_last",0);
421
422 117 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
423
424 117 zc_color_depth = (byte) zc_get_config(cfg_sect,"color_depth",8);
425
426 117 forceExit = (byte) zc_get_config(cfg_sect,"force_exit",0);
427 117 info_opacity = zc_get_config("zc","debug_info_opacity",255);
428 #ifdef _WIN32
429 zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
430 zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
431 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
432 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
433
434 // This one's for Aero
435 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
436
437 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
438 #else //UNIX
439 117 zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
440 117 zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
441 117 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
442 #endif
443 117 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
444 117 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
445
446 117 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
447 117 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
448 117 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
449 117 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
450 117 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
451 117 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
452 117 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
453 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
454 117 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1);
455 117 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
456 117 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
457 117 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
458 117 }
459
460 void save_control_configs(bool kb)
461 {
462 if(kb)
463 {
464 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
465 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
466 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
467 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
468
469 if (!replay_is_replaying())
470 {
471 zc_set_config(ctrl_sect,"key_a",Akey);
472 zc_set_config(ctrl_sect,"key_b",Bkey);
473 zc_set_config(ctrl_sect,"key_s",Skey);
474 zc_set_config(ctrl_sect,"key_l",Lkey);
475 zc_set_config(ctrl_sect,"key_r",Rkey);
476 zc_set_config(ctrl_sect,"key_p",Pkey);
477 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
478 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
479 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
480 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
481 zc_set_config(ctrl_sect,"key_up", DUkey);
482 zc_set_config(ctrl_sect,"key_down", DDkey);
483 zc_set_config(ctrl_sect,"key_left", DLkey);
484 zc_set_config(ctrl_sect,"key_right",DRkey);
485 }
486 }
487 else
488 {
489 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
490 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
491 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
492 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
493 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
494 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
495 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
496 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
497 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
498 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
499 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
500 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
501 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
502 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
503
504 zc_set_config(ctrl_sect,"btn_a",Abtn);
505 zc_set_config(ctrl_sect,"btn_b",Bbtn);
506 zc_set_config(ctrl_sect,"btn_s",Sbtn);
507 zc_set_config(ctrl_sect,"btn_m",Mbtn);
508 zc_set_config(ctrl_sect,"btn_l",Lbtn);
509 zc_set_config(ctrl_sect,"btn_r",Rbtn);
510 zc_set_config(ctrl_sect,"btn_p",Pbtn);
511 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
512 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
513 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
514 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
515
516 zc_set_config(ctrl_sect,"btn_up",DUbtn);
517 zc_set_config(ctrl_sect,"btn_down",DDbtn);
518 zc_set_config(ctrl_sect,"btn_left",DLbtn);
519 zc_set_config(ctrl_sect,"btn_right",DRbtn);
520 }
521 }
522
523 void save_cheatkeys()
524 {
525 char buf[256];
526 for(size_t q = 1; q < Cheat::Last; ++q)
527 {
528 if(!bindable_cheat((Cheat)q)) continue;
529 std::string cheatname = cheat_to_string((Cheat)q);
530 util::lowerstr(cheatname);
531 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
532 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
533 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
534 if(cheatkeys[q][1])
535 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
536 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
537 }
538 }
539
540 void save_game_configs()
541 {
542 packfile_password("");
543
544 zc_set_config("ZCMODULE",qst_module_name,moduledata.module_name);
545
546 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
547 {
548 int o_window_x, o_window_y;
549 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
550 zc_set_config(cfg_sect,"window_x",o_window_x);
551 zc_set_config(cfg_sect,"window_y",o_window_y);
552 }
553
554 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
555 {
556 window_width = al_get_display_width(all_get_display());
557 window_height = al_get_display_height(all_get_display());
558 zc_set_config(cfg_sect,"window_width",window_width);
559 zc_set_config(cfg_sect,"window_height",window_height);
560 }
561
562 zc_set_config(cfg_sect,"load_last",loadlast);
563 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
564
565 flush_config_file();
566 #ifdef __EMSCRIPTEN__
567 em_sync_fs();
568 #endif
569 }
570
571 //----------------------------------------------------------------
572
573 // Timers
574
575 30950 void fps_callback()
576 {
577 30950 lastfps=framecnt;
578 30950 framecnt=0;
579 30950 }
580
581 END_OF_FUNCTION(fps_callback)
582
583 117 int32_t Z_init_timers()
584 {
585 static bool didit = false;
586 const static char *err_str = "Couldn't allocate timer";
587 117 err_str = err_str; //Unused variable warning
588
589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
117 if(didit)
590 return 1;
591
592 117 didit = true;
593
594 LOCK_VARIABLE(lastfps);
595 LOCK_VARIABLE(framecnt);
596 LOCK_FUNCTION(fps_callback);
597
598
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
599 return 0;
600
601 117 return 1;
602 117 }
603
604 void Z_remove_timers()
605 {
606 remove_int(fps_callback);
607 }
608
609 //----------------------------------------------------------------
610
611 void go()
612 {
613 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
614 }
615
616 void comeback()
617 {
618 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
619 }
620
621 void dump_pal(BITMAP *dest)
622 {
623 for(int32_t i=0; i<256; i++)
624 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
625 }
626
627 //----------------------------------------------------------------
628
629 int game_mouse_index = ZCM_BLANK;
630 static bool system_mouse = false;
631 28 bool sys_mouse()
632 {
633 28 system_mouse = true;
634 28 return MouseSprite::set(ZCM_NORMAL);
635 }
636 561 bool game_mouse()
637 {
638 561 system_mouse = false;
639 561 return MouseSprite::set(game_mouse_index);
640 }
641 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
642 {
643 if(!bmp)
644 return;
645 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
646 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
647 if(bmp->w == scaledw && bmp->h == scaledh)
648 user_scale = false;
649 if(user_scale || sys_recolor)
650 {
651 if(!user_scale) scale = 1;
652 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
653 if(user_scale)
654 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
655 else
656 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
657 if(sys_recolor)
658 recolor_mouse(tmpbmp);
659 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
660 destroy_bitmap(tmpbmp);
661 }
662 else
663 {
664 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
665 }
666 }
667
668 //Handles converting the mouse sprite from the .dat file
669 void recolor_mouse(BITMAP* bmp)
670 {
671 for(int32_t x = 0; x < bmp->w; ++x)
672 {
673 for(int32_t y = 0; y < bmp->h; ++y)
674 {
675 int32_t color = getpixel(bmp, x, y);
676 switch(color)
677 {
678 case dvc(1):
679 color = jwin_pal[jcCURSORMISC];
680 break;
681 case dvc(2):
682 color = jwin_pal[jcCURSOROUTLINE];
683 break;
684 case dvc(3):
685 color = jwin_pal[jcCURSORLIGHT];
686 break;
687 case dvc(5):
688 color = jwin_pal[jcCURSORDARK];
689 break;
690 default:
691 continue;
692 }
693 putpixel(bmp, x, y, color);
694 }
695 }
696 }
697 void load_mouse()
698 {
699 PALETTE pal;
700 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
701 if (!cursor_bitmap)
702 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
703
704 enter_sys_pal();
705 MouseSprite::set(-1);
706 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
707 int32_t sz = 16*scale;
708 for(int32_t j = 0; j < 1; ++j)
709 {
710 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
711 if(zcmouse[j])
712 destroy_bitmap(zcmouse[j]);
713 zcmouse[j] = create_bitmap_ex(8,sz,sz);
714 clear_bitmap(zcmouse[j]);
715 clear_bitmap(tmpbmp);
716 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
717 recolor_mouse(tmpbmp);
718 if(sz!=16)
719 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
720 else
721 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
722 destroy_bitmap(tmpbmp);
723 }
724 if(!hw_palette) hw_palette = &RAMpal;
725 zc_set_palette(*hw_palette);
726
727 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
728 clear_bitmap(blankmouse);
729
730 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
731 MouseSprite::assign(ZCM_BLANK, blankmouse);
732 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
733
734 //Reload the mouse
735 if(system_mouse)
736 sys_mouse();
737 else game_mouse();
738
739 destroy_bitmap(blankmouse);
740 destroy_bitmap(cursor_bitmap);
741 exit_sys_pal();
742 }
743
744 // sets the video mode and initializes the palette and mouse sprite
745 117 bool game_vid_mode(int32_t mode,int32_t wait)
746 {
747
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 if (is_headless())
748 117 return true;
749
750 extern int zq_screen_w, zq_screen_h;
751 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
752 {
753 return false;
754 }
755
756 scrx = (resx-320)>>1;
757 scry = (resy-240)>>1;
758 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
759 zcmouse[q] = NULL;
760 load_mouse();
761
762 for(int32_t i=240; i<256; i++)
763 RAMpal[i]=pal_gui[i];
764
765 zc_set_palette(RAMpal);
766 clear_to_color(screen,BLACK);
767
768 rest(wait);
769 return true;
770 117 }
771
772 8 void null_quest()
773 {
774 char qstdat_string[2048];
775 8 strcpy(qstdat_string, "modules/classic/default.qst");
776
777 #ifdef __EMSCRIPTEN__
778 // The quest template data file is not included because it's really big and isn't really needed
779 // for the player, except to initialize some graphics. Those same graphics exist in this quest file,
780 // which is much smaller.
781 strcpy(qstdat_string, "modules/classic/title_gfx.dat");
782 #endif
783
784 8 byte skip_flags[4] = { 0 };
785
786 8 loadquest(qstdat_string,&QHeader,&QMisc,tunes+ZC_MIDI_COUNT,false,skip_flags,0,false);
787 8 }
788
789 8 void init_NES_mode()
790 {
791 8 null_quest();
792 8 }
793
794 //----------------------------------------------------------------
795
796 qword trianglelines[16]=
797 {
798 0x0000000000000000ULL,
799 0xFD00000000000000ULL,
800 0xFDFD000000000000ULL,
801 0xFDFDFD0000000000ULL,
802 0xFDFDFDFD00000000ULL,
803 0xFDFDFDFDFD000000ULL,
804 0xFDFDFDFDFDFD0000ULL,
805 0xFDFDFDFDFDFDFD00ULL,
806 0xFDFDFDFDFDFDFDFDULL,
807 0x00FDFDFDFDFDFDFDULL,
808 0x0000FDFDFDFDFDFDULL,
809 0x000000FDFDFDFDFDULL,
810 0x00000000FDFDFDFDULL,
811 0x0000000000FDFDFDULL,
812 0x000000000000FDFDULL,
813 0x00000000000000FDULL,
814 };
815
816 word screen_triangles[28][32];
817 /*
818 qword triangles[4][16]= //[direction][value]
819 {
820 {
821 0x00000000, 0x10000000, 0x21000000, 0x32100000, 0x43210000, 0x54321000, 0x65432100, 0x76543210, 0x87654321, 0x88765432, 0x88876543, 0x88887654, 0x88888765, 0x88888876, 0x88888887, 0x88888888
822 },
823 {
824 0x00000000, 0xF0000000, 0xEF000000, 0xFDF00000, 0xCFDF0000, 0xBCFDF000, 0xABCFDF00, 0x9ABCFDF0, 0x89ABCFDF, 0x889ABCFD, 0x8889ABCD, 0x88889ABC, 0x888889AB, 0x8888889A, 0x88888889, 0x88888888
825 },
826 {
827 0x00000000, 0x00000001, 0x00000012, 0x00000123, 0x00001234, 0x00012345, 0x00123456, 0x01234567, 0x12345678, 0x23456788, 0x34567888, 0x45678888, 0x56788888, 0x67888888, 0x78888888, 0x88888888
828 },
829 {
830 0x00000000, 0x0000000F, 0x000000FE, 0x00000FED, 0x0000FEDC, 0x000FEDCB, 0x00FEDCBA, 0x0FEDCBA9, 0xFEDCBA98, 0xEDCBA988, 0xDCBA9888, 0xCBA98888, 0xBA988888, 0xA9888888, 0x98888888, 0x88888888
831 }
832 };
833 */
834
835
836 /*
837 byte triangles[4][16][8]= //[direction][value][line]
838 {
839 {
840 {
841 0, 0, 0, 0, 0, 0, 0, 0
842 },
843 {
844 1, 0, 0, 0, 0, 0, 0, 0
845 },
846 {
847 2, 1, 0, 0, 0, 0, 0, 0
848 },
849 {
850 3, 2, 1, 0, 0, 0, 0, 0
851 },
852 {
853 4, 3, 2, 1, 0, 0, 0, 0
854 },
855 {
856 5, 4, 3, 2, 1, 0, 0, 0
857 },
858 {
859 6, 5, 4, 3, 2, 1, 0, 0
860 },
861 {
862 7, 6, 5, 4, 3, 2, 1, 0
863 },
864 {
865 8, 7, 6, 5, 4, 3, 2, 1
866 },
867 {
868 8, 8, 7, 6, 5, 4, 3, 2
869 },
870 {
871 8, 8, 8, 7, 6, 5, 4, 3
872 },
873 {
874 8, 8, 8, 8, 7, 6, 5, 4
875 },
876 {
877 8, 8, 8, 8, 8, 7, 6, 5
878 },
879 {
880 8, 8, 8, 8, 8, 8, 7, 6
881 },
882 {
883 8, 8, 8, 8, 8, 8, 8, 7
884 },
885 {
886 8, 8, 8, 8, 8, 8, 8, 8
887 }
888 },
889 {
890 {
891 0, 0, 0, 0, 0, 0, 0, 0
892 },
893 {
894 15, 0, 0, 0, 0, 0, 0, 0
895 },
896 {
897 14, 15, 0, 0, 0, 0, 0, 0
898 },
899 {
900 13, 14, 15, 0, 0, 0, 0, 0
901 },
902 {
903 12, 13, 14, 15, 0, 0, 0, 0
904 },
905 {
906 11, 12, 13, 14, 15, 0, 0, 0
907 },
908 {
909 10, 11, 12, 13, 14, 15, 0, 0
910 },
911 {
912 9, 10, 11, 12, 13, 14, 15, 0
913 },
914 {
915 8, 9, 10, 11, 12, 13, 14, 15
916 },
917 {
918 8, 8, 9, 10, 11, 12, 13, 14
919 },
920 {
921 8, 8, 8, 9, 10, 11, 12, 13
922 },
923 {
924 8, 8, 8, 8, 9, 10, 11, 12
925 },
926 {
927 8, 8, 8, 8, 8, 9, 10, 11
928 },
929 {
930 8, 8, 8, 8, 8, 8, 9, 10
931 },
932 {
933 8, 8, 8, 8, 8, 8, 8, 9
934 },
935 {
936 8, 8, 8, 8, 8, 8, 8, 8
937 }
938 },
939 {
940 {
941 0, 0, 0, 0, 0, 0, 0, 0
942 },
943 {
944 0, 0, 0, 0, 0, 0, 0, 1
945 },
946 {
947 0, 0, 0, 0, 0, 0, 1, 2
948 },
949 {
950 0, 0, 0, 0, 0, 1, 2, 3
951 },
952 {
953 0, 0, 0, 0, 1, 2, 3, 4
954 },
955 {
956 0, 0, 0, 1, 2, 3, 4, 5
957 },
958 {
959 0, 0, 1, 2, 3, 4, 5, 6
960 },
961 {
962 0, 1, 2, 3, 4, 5, 6, 7
963 },
964 {
965 1, 2, 3, 4, 5, 6, 7, 8
966 },
967 {
968 2, 3, 4, 5, 6, 7, 8, 8
969 },
970 {
971 3, 4, 5, 6, 7, 8, 8, 8
972 },
973 {
974 4, 5, 6, 7, 8, 8, 8, 8
975 },
976 {
977 5, 6, 7, 8, 8, 8, 8, 8
978 },
979 {
980 6, 7, 8, 8, 8, 8, 8, 8
981 },
982 {
983 7, 8, 8, 8, 8, 8, 8, 8
984 },
985 {
986 8, 8, 8, 8, 8, 8, 8, 8
987 }
988 },
989 {
990 {
991 0, 0, 0, 0, 0, 0, 0, 0
992 },
993 {
994 0, 0, 0, 0, 0, 0, 0, 15
995 },
996 {
997 0, 0, 0, 0, 0, 0, 15, 14
998 },
999 {
1000 0, 0, 0, 0, 0, 15, 14, 13
1001 },
1002 {
1003 0, 0, 0, 0, 15, 14, 13, 12
1004 },
1005 {
1006 0, 0, 0, 15, 14, 13, 12, 11
1007 },
1008 {
1009 0, 0, 15, 14, 13, 12, 11, 10
1010 },
1011 {
1012 0, 15, 14, 13, 12, 11, 10, 9
1013 },
1014 {
1015 15, 14, 13, 12, 11, 10, 9, 8
1016 },
1017 {
1018 14, 13, 12, 11, 10, 9, 8, 8
1019 },
1020 {
1021 13, 12, 11, 10, 9, 8, 8, 8
1022 },
1023 {
1024 12, 11, 10, 9, 8, 8, 8, 8
1025 },
1026 {
1027 11, 10, 9, 8, 8, 8, 8, 8
1028 },
1029 {
1030 10, 9, 8, 8, 8, 8, 8, 8
1031 },
1032 {
1033 9, 8, 8, 8, 8, 8, 8, 8
1034 },
1035 {
1036 8, 8, 8, 8, 8, 8, 8, 8
1037 }
1038 }
1039 };
1040 */
1041
1042
1043
1044 /*
1045 for (int32_t blockrow=0; blockrow<30; ++i)
1046 {
1047 for (int32_t linerow=0; linerow<8; ++i)
1048 {
1049 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1050 for (int32_t blockcolumn=0; blockcolumn<40; ++i)
1051 {
1052 triangleline=triangles[0][screen_triangles[blockrow][blockcolumn]][linerow];
1053 ++triangleline;
1054 }
1055 }
1056 }
1057 */
1058
1059 // the ULL suffixes are to prevent this warning:
1060 // warning: integer constant is too large for "int32_t" type
1061
1062 qword triangles[4][16][8]= //[direction][value][line]
1063 {
1064 {
1065 {
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL,
1070 0x0000000000000000ULL,
1071 0x0000000000000000ULL,
1072 0x0000000000000000ULL,
1073 0x0000000000000000ULL
1074 },
1075 {
1076 0xFD00000000000000ULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL,
1080 0x0000000000000000ULL,
1081 0x0000000000000000ULL,
1082 0x0000000000000000ULL,
1083 0x0000000000000000ULL
1084 },
1085 {
1086 0xFDFD000000000000ULL,
1087 0xFD00000000000000ULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL,
1090 0x0000000000000000ULL,
1091 0x0000000000000000ULL,
1092 0x0000000000000000ULL,
1093 0x0000000000000000ULL
1094 },
1095 {
1096 0xFDFDFD0000000000ULL,
1097 0xFDFD000000000000ULL,
1098 0xFD00000000000000ULL,
1099 0x0000000000000000ULL,
1100 0x0000000000000000ULL,
1101 0x0000000000000000ULL,
1102 0x0000000000000000ULL,
1103 0x0000000000000000ULL
1104 },
1105 {
1106 0xFDFDFDFD00000000ULL,
1107 0xFDFDFD0000000000ULL,
1108 0xFDFD000000000000ULL,
1109 0xFD00000000000000ULL,
1110 0x0000000000000000ULL,
1111 0x0000000000000000ULL,
1112 0x0000000000000000ULL,
1113 0x0000000000000000ULL
1114 },
1115 {
1116 0xFDFDFDFDFD000000ULL,
1117 0xFDFDFDFD00000000ULL,
1118 0xFDFDFD0000000000ULL,
1119 0xFDFD000000000000ULL,
1120 0xFD00000000000000ULL,
1121 0x0000000000000000ULL,
1122 0x0000000000000000ULL,
1123 0x0000000000000000ULL
1124 },
1125 {
1126 0xFDFDFDFDFDFD0000ULL,
1127 0xFDFDFDFDFD000000ULL,
1128 0xFDFDFDFD00000000ULL,
1129 0xFDFDFD0000000000ULL,
1130 0xFDFD000000000000ULL,
1131 0xFD00000000000000ULL,
1132 0x0000000000000000ULL,
1133 0x0000000000000000ULL
1134 },
1135 {
1136 0xFDFDFDFDFDFDFD00ULL,
1137 0xFDFDFDFDFDFD0000ULL,
1138 0xFDFDFDFDFD000000ULL,
1139 0xFDFDFDFD00000000ULL,
1140 0xFDFDFD0000000000ULL,
1141 0xFDFD000000000000ULL,
1142 0xFD00000000000000ULL,
1143 0x0000000000000000ULL
1144 },
1145 {
1146 0xFDFDFDFDFDFDFDFDULL,
1147 0xFDFDFDFDFDFDFD00ULL,
1148 0xFDFDFDFDFDFD0000ULL,
1149 0xFDFDFDFDFD000000ULL,
1150 0xFDFDFDFD00000000ULL,
1151 0xFDFDFD0000000000ULL,
1152 0xFDFD000000000000ULL,
1153 0xFD00000000000000ULL
1154 },
1155 {
1156 0xFDFDFDFDFDFDFDFDULL,
1157 0xFDFDFDFDFDFDFDFDULL,
1158 0xFDFDFDFDFDFDFD00ULL,
1159 0xFDFDFDFDFDFD0000ULL,
1160 0xFDFDFDFDFD000000ULL,
1161 0xFDFDFDFD00000000ULL,
1162 0xFDFDFD0000000000ULL,
1163 0xFDFD000000000000ULL
1164 },
1165 {
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0xFDFDFDFDFDFDFDFDULL,
1168 0xFDFDFDFDFDFDFDFDULL,
1169 0xFDFDFDFDFDFDFD00ULL,
1170 0xFDFDFDFDFDFD0000ULL,
1171 0xFDFDFDFDFD000000ULL,
1172 0xFDFDFDFD00000000ULL,
1173 0xFDFDFD0000000000ULL
1174 },
1175 {
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0xFDFDFDFDFDFDFDFDULL,
1179 0xFDFDFDFDFDFDFDFDULL,
1180 0xFDFDFDFDFDFDFD00ULL,
1181 0xFDFDFDFDFDFD0000ULL,
1182 0xFDFDFDFDFD000000ULL,
1183 0xFDFDFDFD00000000ULL
1184 },
1185 {
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0xFDFDFDFDFDFDFDFDULL,
1191 0xFDFDFDFDFDFDFD00ULL,
1192 0xFDFDFDFDFDFD0000ULL,
1193 0xFDFDFDFDFD000000ULL
1194 },
1195 {
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL,
1200 0xFDFDFDFDFDFDFDFDULL,
1201 0xFDFDFDFDFDFDFDFDULL,
1202 0xFDFDFDFDFDFDFD00ULL,
1203 0xFDFDFDFDFDFD0000ULL
1204 },
1205 {
1206 0xFDFDFDFDFDFDFDFDULL,
1207 0xFDFDFDFDFDFDFDFDULL,
1208 0xFDFDFDFDFDFDFDFDULL,
1209 0xFDFDFDFDFDFDFDFDULL,
1210 0xFDFDFDFDFDFDFDFDULL,
1211 0xFDFDFDFDFDFDFDFDULL,
1212 0xFDFDFDFDFDFDFDFDULL,
1213 0xFDFDFDFDFDFDFD00ULL
1214 },
1215 {
1216 0xFDFDFDFDFDFDFDFDULL,
1217 0xFDFDFDFDFDFDFDFDULL,
1218 0xFDFDFDFDFDFDFDFDULL,
1219 0xFDFDFDFDFDFDFDFDULL,
1220 0xFDFDFDFDFDFDFDFDULL,
1221 0xFDFDFDFDFDFDFDFDULL,
1222 0xFDFDFDFDFDFDFDFDULL,
1223 0xFDFDFDFDFDFDFDFDULL
1224 }
1225 },
1226 {
1227 {
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0x0000000000000000ULL,
1231 0x0000000000000000ULL,
1232 0x0000000000000000ULL,
1233 0x0000000000000000ULL,
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL
1236 },
1237 {
1238 0x00000000000000FDULL,
1239 0x0000000000000000ULL,
1240 0x0000000000000000ULL,
1241 0x0000000000000000ULL,
1242 0x0000000000000000ULL,
1243 0x0000000000000000ULL,
1244 0x0000000000000000ULL,
1245 0x0000000000000000ULL
1246 },
1247 {
1248 0x000000000000FDFDULL,
1249 0x00000000000000FDULL,
1250 0x0000000000000000ULL,
1251 0x0000000000000000ULL,
1252 0x0000000000000000ULL,
1253 0x0000000000000000ULL,
1254 0x0000000000000000ULL,
1255 0x0000000000000000ULL
1256 },
1257 {
1258 0x0000000000FDFDFDULL,
1259 0x000000000000FDFDULL,
1260 0x00000000000000FDULL,
1261 0x0000000000000000ULL,
1262 0x0000000000000000ULL,
1263 0x0000000000000000ULL,
1264 0x0000000000000000ULL,
1265 0x0000000000000000ULL
1266 },
1267 {
1268 0x00000000FDFDFDFDULL,
1269 0x0000000000FDFDFDULL,
1270 0x000000000000FDFDULL,
1271 0x00000000000000FDULL,
1272 0x0000000000000000ULL,
1273 0x0000000000000000ULL,
1274 0x0000000000000000ULL,
1275 0x0000000000000000ULL
1276 },
1277 {
1278 0x000000FDFDFDFDFDULL,
1279 0x00000000FDFDFDFDULL,
1280 0x0000000000FDFDFDULL,
1281 0x000000000000FDFDULL,
1282 0x00000000000000FDULL,
1283 0x0000000000000000ULL,
1284 0x0000000000000000ULL,
1285 0x0000000000000000ULL
1286 },
1287 {
1288 0x0000FDFDFDFDFDFDULL,
1289 0x000000FDFDFDFDFDULL,
1290 0x00000000FDFDFDFDULL,
1291 0x0000000000FDFDFDULL,
1292 0x000000000000FDFDULL,
1293 0x00000000000000FDULL,
1294 0x0000000000000000ULL,
1295 0x0000000000000000ULL
1296 },
1297 {
1298 0x00FDFDFDFDFDFDFDULL,
1299 0x0000FDFDFDFDFDFDULL,
1300 0x000000FDFDFDFDFDULL,
1301 0x00000000FDFDFDFDULL,
1302 0x0000000000FDFDFDULL,
1303 0x000000000000FDFDULL,
1304 0x00000000000000FDULL,
1305 0x0000000000000000ULL
1306 },
1307 {
1308 0xFDFDFDFDFDFDFDFDULL,
1309 0x00FDFDFDFDFDFDFDULL,
1310 0x0000FDFDFDFDFDFDULL,
1311 0x000000FDFDFDFDFDULL,
1312 0x00000000FDFDFDFDULL,
1313 0x0000000000FDFDFDULL,
1314 0x000000000000FDFDULL,
1315 0x00000000000000FDULL
1316 },
1317 {
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL,
1320 0x00FDFDFDFDFDFDFDULL,
1321 0x0000FDFDFDFDFDFDULL,
1322 0x000000FDFDFDFDFDULL,
1323 0x00000000FDFDFDFDULL,
1324 0x0000000000FDFDFDULL,
1325 0x000000000000FDFDULL
1326 },
1327 {
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0x00FDFDFDFDFDFDFDULL,
1332 0x0000FDFDFDFDFDFDULL,
1333 0x000000FDFDFDFDFDULL,
1334 0x00000000FDFDFDFDULL,
1335 0x0000000000FDFDFDULL
1336 },
1337 {
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL,
1342 0x00FDFDFDFDFDFDFDULL,
1343 0x0000FDFDFDFDFDFDULL,
1344 0x000000FDFDFDFDFDULL,
1345 0x00000000FDFDFDFDULL
1346 },
1347 {
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0xFDFDFDFDFDFDFDFDULL,
1353 0x00FDFDFDFDFDFDFDULL,
1354 0x0000FDFDFDFDFDFDULL,
1355 0x000000FDFDFDFDFDULL
1356 },
1357 {
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL,
1362 0xFDFDFDFDFDFDFDFDULL,
1363 0xFDFDFDFDFDFDFDFDULL,
1364 0x00FDFDFDFDFDFDFDULL,
1365 0x0000FDFDFDFDFDFDULL
1366 },
1367 {
1368 0xFDFDFDFDFDFDFDFDULL,
1369 0xFDFDFDFDFDFDFDFDULL,
1370 0xFDFDFDFDFDFDFDFDULL,
1371 0xFDFDFDFDFDFDFDFDULL,
1372 0xFDFDFDFDFDFDFDFDULL,
1373 0xFDFDFDFDFDFDFDFDULL,
1374 0xFDFDFDFDFDFDFDFDULL,
1375 0x00FDFDFDFDFDFDFDULL
1376 },
1377 {
1378 0xFDFDFDFDFDFDFDFDULL,
1379 0xFDFDFDFDFDFDFDFDULL,
1380 0xFDFDFDFDFDFDFDFDULL,
1381 0xFDFDFDFDFDFDFDFDULL,
1382 0xFDFDFDFDFDFDFDFDULL,
1383 0xFDFDFDFDFDFDFDFDULL,
1384 0xFDFDFDFDFDFDFDFDULL,
1385 0xFDFDFDFDFDFDFDFDULL
1386 }
1387 },
1388 {
1389 {
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x0000000000000000ULL,
1393 0x0000000000000000ULL,
1394 0x0000000000000000ULL,
1395 0x0000000000000000ULL,
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL
1398 },
1399 {
1400 0x0000000000000000ULL,
1401 0x0000000000000000ULL,
1402 0x0000000000000000ULL,
1403 0x0000000000000000ULL,
1404 0x0000000000000000ULL,
1405 0x0000000000000000ULL,
1406 0x0000000000000000ULL,
1407 0xFD00000000000000ULL
1408 },
1409 {
1410 0x0000000000000000ULL,
1411 0x0000000000000000ULL,
1412 0x0000000000000000ULL,
1413 0x0000000000000000ULL,
1414 0x0000000000000000ULL,
1415 0x0000000000000000ULL,
1416 0xFD00000000000000ULL,
1417 0xFDFD000000000000ULL
1418 },
1419 {
1420 0x0000000000000000ULL,
1421 0x0000000000000000ULL,
1422 0x0000000000000000ULL,
1423 0x0000000000000000ULL,
1424 0x0000000000000000ULL,
1425 0xFD00000000000000ULL,
1426 0xFDFD000000000000ULL,
1427 0xFDFDFD0000000000ULL
1428 },
1429 {
1430 0x0000000000000000ULL,
1431 0x0000000000000000ULL,
1432 0x0000000000000000ULL,
1433 0x0000000000000000ULL,
1434 0xFD00000000000000ULL,
1435 0xFDFD000000000000ULL,
1436 0xFDFDFD0000000000ULL,
1437 0xFDFDFDFD00000000ULL
1438 },
1439 {
1440 0x0000000000000000ULL,
1441 0x0000000000000000ULL,
1442 0x0000000000000000ULL,
1443 0xFD00000000000000ULL,
1444 0xFDFD000000000000ULL,
1445 0xFDFDFD0000000000ULL,
1446 0xFDFDFDFD00000000ULL,
1447 0xFDFDFDFDFD000000ULL
1448 },
1449 {
1450 0x0000000000000000ULL,
1451 0x0000000000000000ULL,
1452 0xFD00000000000000ULL,
1453 0xFDFD000000000000ULL,
1454 0xFDFDFD0000000000ULL,
1455 0xFDFDFDFD00000000ULL,
1456 0xFDFDFDFDFD000000ULL,
1457 0xFDFDFDFDFDFD0000ULL
1458 },
1459 {
1460 0x0000000000000000ULL,
1461 0xFD00000000000000ULL,
1462 0xFDFD000000000000ULL,
1463 0xFDFDFD0000000000ULL,
1464 0xFDFDFDFD00000000ULL,
1465 0xFDFDFDFDFD000000ULL,
1466 0xFDFDFDFDFDFD0000ULL,
1467 0xFDFDFDFDFDFDFD00ULL
1468 },
1469 {
1470 0xFD00000000000000ULL,
1471 0xFDFD000000000000ULL,
1472 0xFDFDFD0000000000ULL,
1473 0xFDFDFDFD00000000ULL,
1474 0xFDFDFDFDFD000000ULL,
1475 0xFDFDFDFDFDFD0000ULL,
1476 0xFDFDFDFDFDFDFD00ULL,
1477 0xFDFDFDFDFDFDFDFDULL
1478 },
1479 {
1480 0xFDFD000000000000ULL,
1481 0xFDFDFD0000000000ULL,
1482 0xFDFDFDFD00000000ULL,
1483 0xFDFDFDFDFD000000ULL,
1484 0xFDFDFDFDFDFD0000ULL,
1485 0xFDFDFDFDFDFDFD00ULL,
1486 0xFDFDFDFDFDFDFDFDULL,
1487 0xFDFDFDFDFDFDFDFDULL
1488 },
1489 {
1490 0xFDFDFD0000000000ULL,
1491 0xFDFDFDFD00000000ULL,
1492 0xFDFDFDFDFD000000ULL,
1493 0xFDFDFDFDFDFD0000ULL,
1494 0xFDFDFDFDFDFDFD00ULL,
1495 0xFDFDFDFDFDFDFDFDULL,
1496 0xFDFDFDFDFDFDFDFDULL,
1497 0xFDFDFDFDFDFDFDFDULL
1498 },
1499 {
1500 0xFDFDFDFD00000000ULL,
1501 0xFDFDFDFDFD000000ULL,
1502 0xFDFDFDFDFDFD0000ULL,
1503 0xFDFDFDFDFDFDFD00ULL,
1504 0xFDFDFDFDFDFDFDFDULL,
1505 0xFDFDFDFDFDFDFDFDULL,
1506 0xFDFDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL
1508 },
1509 {
1510 0xFDFDFDFDFD000000ULL,
1511 0xFDFDFDFDFDFD0000ULL,
1512 0xFDFDFDFDFDFDFD00ULL,
1513 0xFDFDFDFDFDFDFDFDULL,
1514 0xFDFDFDFDFDFDFDFDULL,
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL
1518 },
1519 {
1520 0xFDFDFDFDFDFD0000ULL,
1521 0xFDFDFDFDFDFDFD00ULL,
1522 0xFDFDFDFDFDFDFDFDULL,
1523 0xFDFDFDFDFDFDFDFDULL,
1524 0xFDFDFDFDFDFDFDFDULL,
1525 0xFDFDFDFDFDFDFDFDULL,
1526 0xFDFDFDFDFDFDFDFDULL,
1527 0xFDFDFDFDFDFDFDFDULL
1528 },
1529 {
1530 0xFDFDFDFDFDFDFD00ULL,
1531 0xFDFDFDFDFDFDFDFDULL,
1532 0xFDFDFDFDFDFDFDFDULL,
1533 0xFDFDFDFDFDFDFDFDULL,
1534 0xFDFDFDFDFDFDFDFDULL,
1535 0xFDFDFDFDFDFDFDFDULL,
1536 0xFDFDFDFDFDFDFDFDULL,
1537 0xFDFDFDFDFDFDFDFDULL
1538 },
1539 {
1540 0xFDFDFDFDFDFDFDFDULL,
1541 0xFDFDFDFDFDFDFDFDULL,
1542 0xFDFDFDFDFDFDFDFDULL,
1543 0xFDFDFDFDFDFDFDFDULL,
1544 0xFDFDFDFDFDFDFDFDULL,
1545 0xFDFDFDFDFDFDFDFDULL,
1546 0xFDFDFDFDFDFDFDFDULL,
1547 0xFDFDFDFDFDFDFDFDULL
1548 }
1549 },
1550 {
1551 {
1552 0x0000000000000000ULL,
1553 0x0000000000000000ULL,
1554 0x0000000000000000ULL,
1555 0x0000000000000000ULL,
1556 0x0000000000000000ULL,
1557 0x0000000000000000ULL,
1558 0x0000000000000000ULL,
1559 0x0000000000000000ULL
1560 },
1561 {
1562 0x0000000000000000ULL,
1563 0x0000000000000000ULL,
1564 0x0000000000000000ULL,
1565 0x0000000000000000ULL,
1566 0x0000000000000000ULL,
1567 0x0000000000000000ULL,
1568 0x0000000000000000ULL,
1569 0x00000000000000FDULL
1570 },
1571 {
1572 0x0000000000000000ULL,
1573 0x0000000000000000ULL,
1574 0x0000000000000000ULL,
1575 0x0000000000000000ULL,
1576 0x0000000000000000ULL,
1577 0x0000000000000000ULL,
1578 0x00000000000000FDULL,
1579 0x000000000000FDFDULL
1580 },
1581 {
1582 0x0000000000000000ULL,
1583 0x0000000000000000ULL,
1584 0x0000000000000000ULL,
1585 0x0000000000000000ULL,
1586 0x0000000000000000ULL,
1587 0x00000000000000FDULL,
1588 0x000000000000FDFDULL,
1589 0x0000000000FDFDFDULL
1590 },
1591 {
1592 0x0000000000000000ULL,
1593 0x0000000000000000ULL,
1594 0x0000000000000000ULL,
1595 0x0000000000000000ULL,
1596 0x00000000000000FDULL,
1597 0x000000000000FDFDULL,
1598 0x0000000000FDFDFDULL,
1599 0x00000000FDFDFDFDULL
1600 },
1601 {
1602 0x0000000000000000ULL,
1603 0x0000000000000000ULL,
1604 0x0000000000000000ULL,
1605 0x00000000000000FDULL,
1606 0x000000000000FDFDULL,
1607 0x0000000000FDFDFDULL,
1608 0x00000000FDFDFDFDULL,
1609 0x000000FDFDFDFDFDULL
1610 },
1611 {
1612 0x0000000000000000ULL,
1613 0x0000000000000000ULL,
1614 0x00000000000000FDULL,
1615 0x000000000000FDFDULL,
1616 0x0000000000FDFDFDULL,
1617 0x00000000FDFDFDFDULL,
1618 0x000000FDFDFDFDFDULL,
1619 0x0000FDFDFDFDFDFDULL
1620 },
1621 {
1622 0x0000000000000000ULL,
1623 0x00000000000000FDULL,
1624 0x000000000000FDFDULL,
1625 0x0000000000FDFDFDULL,
1626 0x00000000FDFDFDFDULL,
1627 0x000000FDFDFDFDFDULL,
1628 0x0000FDFDFDFDFDFDULL,
1629 0x00FDFDFDFDFDFDFDULL
1630 },
1631 {
1632 0x00000000000000FDULL,
1633 0x000000000000FDFDULL,
1634 0x0000000000FDFDFDULL,
1635 0x00000000FDFDFDFDULL,
1636 0x000000FDFDFDFDFDULL,
1637 0x0000FDFDFDFDFDFDULL,
1638 0x00FDFDFDFDFDFDFDULL,
1639 0xFDFDFDFDFDFDFDFDULL
1640 },
1641 {
1642 0x000000000000FDFDULL,
1643 0x0000000000FDFDFDULL,
1644 0x00000000FDFDFDFDULL,
1645 0x000000FDFDFDFDFDULL,
1646 0x0000FDFDFDFDFDFDULL,
1647 0x00FDFDFDFDFDFDFDULL,
1648 0xFDFDFDFDFDFDFDFDULL,
1649 0xFDFDFDFDFDFDFDFDULL
1650 },
1651 {
1652 0x0000000000FDFDFDULL,
1653 0x00000000FDFDFDFDULL,
1654 0x000000FDFDFDFDFDULL,
1655 0x0000FDFDFDFDFDFDULL,
1656 0x00FDFDFDFDFDFDFDULL,
1657 0xFDFDFDFDFDFDFDFDULL,
1658 0xFDFDFDFDFDFDFDFDULL,
1659 0xFDFDFDFDFDFDFDFDULL
1660 },
1661 {
1662 0x00000000FDFDFDFDULL,
1663 0x000000FDFDFDFDFDULL,
1664 0x0000FDFDFDFDFDFDULL,
1665 0x00FDFDFDFDFDFDFDULL,
1666 0xFDFDFDFDFDFDFDFDULL,
1667 0xFDFDFDFDFDFDFDFDULL,
1668 0xFDFDFDFDFDFDFDFDULL,
1669 0xFDFDFDFDFDFDFDFDULL
1670 },
1671 {
1672 0x000000FDFDFDFDFDULL,
1673 0x0000FDFDFDFDFDFDULL,
1674 0x00FDFDFDFDFDFDFDULL,
1675 0xFDFDFDFDFDFDFDFDULL,
1676 0xFDFDFDFDFDFDFDFDULL,
1677 0xFDFDFDFDFDFDFDFDULL,
1678 0xFDFDFDFDFDFDFDFDULL,
1679 0xFDFDFDFDFDFDFDFDULL
1680 },
1681 {
1682 0x0000FDFDFDFDFDFDULL,
1683 0x00FDFDFDFDFDFDFDULL,
1684 0xFDFDFDFDFDFDFDFDULL,
1685 0xFDFDFDFDFDFDFDFDULL,
1686 0xFDFDFDFDFDFDFDFDULL,
1687 0xFDFDFDFDFDFDFDFDULL,
1688 0xFDFDFDFDFDFDFDFDULL,
1689 0xFDFDFDFDFDFDFDFDULL
1690 },
1691 {
1692 0x00FDFDFDFDFDFDFDULL,
1693 0xFDFDFDFDFDFDFDFDULL,
1694 0xFDFDFDFDFDFDFDFDULL,
1695 0xFDFDFDFDFDFDFDFDULL,
1696 0xFDFDFDFDFDFDFDFDULL,
1697 0xFDFDFDFDFDFDFDFDULL,
1698 0xFDFDFDFDFDFDFDFDULL,
1699 0xFDFDFDFDFDFDFDFDULL
1700 },
1701 {
1702 0xFDFDFDFDFDFDFDFDULL,
1703 0xFDFDFDFDFDFDFDFDULL,
1704 0xFDFDFDFDFDFDFDFDULL,
1705 0xFDFDFDFDFDFDFDFDULL,
1706 0xFDFDFDFDFDFDFDFDULL,
1707 0xFDFDFDFDFDFDFDFDULL,
1708 0xFDFDFDFDFDFDFDFDULL,
1709 0xFDFDFDFDFDFDFDFDULL
1710 }
1711 }
1712 };
1713
1714 int32_t black_opening_count=0;
1715 int32_t black_opening_x,black_opening_y;
1716 int32_t black_opening_shape;
1717
1718 1508 int32_t choose_opening_shape()
1719 {
1720 // First, count how many bits are set
1721 1508 int32_t numBits=0;
1722 int32_t bitCounter;
1723
1724
2/2
✓ Branch 0 taken 7540 times.
✓ Branch 1 taken 1508 times.
9048 for(int32_t i=0; i<bosMAX; i++)
1725 {
1726
2/2
✓ Branch 0 taken 5816 times.
✓ Branch 1 taken 1724 times.
7540 if(COOLSCROLL&(1<<i))
1727 1724 numBits++;
1728 7540 }
1729
1730 // Shouldn't happen...
1731
1/2
✓ Branch 0 taken 1508 times.
✗ Branch 1 not taken.
1508 if(numBits==0)
1732 return bosCIRCLE;
1733
1734 // Pick a bit
1735 1508 bitCounter=zc_rand()%numBits+1;
1736
1737
2/2
✓ Branch 0 taken 1993 times.
✓ Branch 1 taken 26 times.
2019 for(int32_t i=0; i<bosMAX; i++)
1738 {
1739 // If this bit is set, decrement the bit counter
1740
2/2
✓ Branch 0 taken 355 times.
✓ Branch 1 taken 1638 times.
1993 if(COOLSCROLL&(1<<i))
1741 1638 bitCounter--;
1742
1743 // When the counter hits 0, return a value based on
1744 // which bit it stopped on.
1745 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1746
2/2
✓ Branch 0 taken 1482 times.
✓ Branch 1 taken 511 times.
1993 if(bitCounter==0)
1747 1482 return i;
1748 511 }
1749
1750 // Shouldn't be necessary, but the compiler might complain, at least
1751 26 return bosCIRCLE;
1752 1508 }
1753
1754 396 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1755 {
1756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 396 times.
396 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1757
1758 396 int32_t w=256, h=224;
1759 396 int32_t blockrows=28, blockcolumns=32;
1760 396 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1761
1762
2/2
✓ Branch 0 taken 11088 times.
✓ Branch 1 taken 396 times.
11484 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1763 {
1764
2/2
✓ Branch 0 taken 354816 times.
✓ Branch 1 taken 11088 times.
365904 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1765 {
1766
2/2
✓ Branch 0 taken 147229 times.
✓ Branch 1 taken 207587 times.
354816 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1767 354816 }
1768 11088 }
1769
1770 396 black_opening_count = 66;
1771 396 black_opening_x = x;
1772 396 black_opening_y = y;
1773 396 lensclk = 0;
1774 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1775
1776
1777
1/2
✓ Branch 0 taken 396 times.
✗ Branch 1 not taken.
396 if(black_opening_shape == bosFADEBLACK)
1778 {
1779 refreshTints();
1780 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1781 }
1782
1/2
✓ Branch 0 taken 396 times.
✗ Branch 1 not taken.
396 if(wait)
1783 {
1784 FFCore.warpScriptCheck();
1785 for(int32_t i=0; i<66; i++)
1786 {
1787 draw_screen(tmpscr);
1788 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1789 advanceframe(true);
1790
1791 if(Quit)
1792 {
1793 break;
1794 }
1795 }
1796 }
1797 396 }
1798
1799 1112 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1800 {
1801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1112 times.
1112 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1802
1803 1112 int32_t w=256, h=224;
1804 1112 int32_t blockrows=28, blockcolumns=32;
1805 1112 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1806
1807
2/2
✓ Branch 0 taken 31136 times.
✓ Branch 1 taken 1112 times.
32248 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1808 {
1809
2/2
✓ Branch 0 taken 996352 times.
✓ Branch 1 taken 31136 times.
1027488 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1810 {
1811
2/2
✓ Branch 0 taken 507221 times.
✓ Branch 1 taken 489131 times.
996352 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1812 996352 }
1813 31136 }
1814
1815 1112 black_opening_count = -66;
1816 1112 black_opening_x = x;
1817 1112 black_opening_y = y;
1818 1112 lensclk = 0;
1819
1/2
✓ Branch 0 taken 1112 times.
✗ Branch 1 not taken.
1112 if(black_opening_shape == bosFADEBLACK)
1820 {
1821 refreshTints();
1822 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1823 }
1824
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 913 times.
1112 if(wait)
1825 {
1826 913 FFCore.warpScriptCheck();
1827
2/2
✓ Branch 0 taken 913 times.
✓ Branch 1 taken 60258 times.
61171 for(int32_t i=0; i<66; i++)
1828 {
1829 60258 draw_screen(tmpscr);
1830 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
1831 60258 advanceframe(true);
1832
1833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60258 times.
60258 if(Quit)
1834 {
1835 break;
1836 }
1837 60258 }
1838 913 }
1839 1112 }
1840
1841 99528 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1842 {
1843 99528 clear_to_color(tmp_scr,BLACK);
1844 99528 int32_t w=256, h=224;
1845
1846
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 858 times.
✓ Branch 2 taken 660 times.
✓ Branch 3 taken 7656 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 90354 times.
99528 switch(black_opening_shape)
1847 {
1848 case bosOVAL:
1849 {
1850 858 double new_w=(w/2)+abs(w/2-x);
1851 858 double new_h=(h/2)+abs(h/2-y);
1852 858 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1853 858 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1854 858 break;
1855 }
1856
1857 case bosTRIANGLE:
1858 {
1859 660 double new_w=(w/2)+abs(w/2-x);
1860 660 double new_h=(h/2)+abs(h/2-y);
1861 660 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1862 660 double P2= (PI/2);
1863 660 double P23=(2*PI/3);
1864 660 double P43=(4*PI/3);
1865 660 double Pa= (-4*PI*a/(3*max_a));
1866 660 double angle=P2+Pa;
1867 660 double a0=angle;
1868 660 double a2=angle+P23;
1869 660 double a4=angle+P43;
1870 1320 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1871 660 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1872 660 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1873 0);
1874 660 break;
1875 }
1876
1877 case bosSMAS:
1878 {
1879
2/2
✓ Branch 0 taken 4158 times.
✓ Branch 1 taken 3498 times.
7656 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1880
1881
2/2
✓ Branch 0 taken 214368 times.
✓ Branch 1 taken 7656 times.
222024 for(int32_t blockrow=0; blockrow<28; ++blockrow) //30
1882 {
1883
2/2
✓ Branch 0 taken 1714944 times.
✓ Branch 1 taken 214368 times.
1929312 for(int32_t linerow=0; linerow<8; ++linerow)
1884 {
1885 1714944 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1886
1887
2/2
✓ Branch 0 taken 54878208 times.
✓ Branch 1 taken 1714944 times.
56593152 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1888 {
1889 164634624 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1890
6/6
✓ Branch 0 taken 39546648 times.
✓ Branch 1 taken 15331560 times.
✓ Branch 2 taken 35934032 times.
✓ Branch 3 taken 18944176 times.
✓ Branch 4 taken 20602472 times.
✓ Branch 5 taken 15331560 times.
54878208 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1891 54878208 [linerow];
1892 54878208 ++triangleline;
1893
1894
2/2
✓ Branch 0 taken 48018432 times.
✓ Branch 1 taken 6859776 times.
54878208 if(linerow==0)
1895 {
1896 6859776 }
1897 54878208 }
1898 1714944 }
1899 214368 }
1900
1901 7656 break;
1902 }
1903
1904 case bosFADEBLACK:
1905 {
1906 if(black_opening_count<0)
1907 {
1908 black_fade(zc_min(-black_opening_count,63));
1909 }
1910 else if(black_opening_count>0)
1911 {
1912 black_fade(63-zc_max(black_opening_count-3,0));
1913 }
1914 else black_fade(0);
1915 return; //no blitting from tmp_scr!
1916 }
1917
1918 90354 case bosCIRCLE:
1919 default:
1920 {
1921 90354 double new_w=(w/2)+abs(w/2-x);
1922 90354 double new_h=(h/2)+abs(h/2-y);
1923 90354 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1924 //circlefill(tmp_scr,x,y,a<<3,0);
1925 90354 circlefill(tmp_scr,x,y,r,0);
1926 90354 break;
1927 }
1928 }
1929
1930 99528 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1931 99528 }
1932
1933
1934 void black_fade(int32_t fadeamnt)
1935 {
1936 for(int32_t i=0; i < 0xEF; i++)
1937 {
1938 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,63);
1939 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,63);
1940 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,63);
1941 }
1942
1943 refreshpal = true;
1944 }
1945
1946 //----------------------------------------------------------------
1947
1948 38831720 bool item_disabled(int32_t item) //is this item disabled?
1949 {
1950
2/2
✓ Branch 0 taken 1832457 times.
✓ Branch 1 taken 36999263 times.
38831720 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1951 }
1952
1953 7618361 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1954 {
1955
2/2
✓ Branch 0 taken 135248 times.
✓ Branch 1 taken 7483113 times.
7618361 if(current_item(item_type, true) >=item)
1956 {
1957 135248 return true;
1958 }
1959
1960 7483113 return false;
1961 7618361 }
1962
1963 25026143 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1964 {
1965
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 26467 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3220277 times.
✓ Branch 6 taken 16170214 times.
✓ Branch 7 taken 5493498 times.
✓ Branch 8 taken 115687 times.
25026143 switch(item_type)
1966 {
1967 case itype_bomb:
1968 case itype_sbomb:
1969 {
1970 int32_t itemid = getItemID(itemsbuf, item_type, it);
1971
1972 if(itemid == -1)
1973 return false;
1974
1975 return (game->get_item(itemid));
1976 }
1977
1978 case itype_clock:
1979 {
1980 26467 int32_t itemid = getItemID(itemsbuf, item_type, it);
1981
1982
2/4
✓ Branch 0 taken 26467 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26467 times.
✗ Branch 3 not taken.
26467 if(itemid != -1 && (itemsbuf[itemid].flags & ITEM_FLAG1)) //Active clock
1983 return (game->get_item(itemid));
1984 26467 return Hero.getClock()?1:0;
1985 }
1986
1987 case itype_key:
1988 return (game->get_keys()>0);
1989
1990 case itype_magiccontainer:
1991 return (game->get_maxmagic()>=game->get_mp_per_block());
1992
1993 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1994 {
1995
2/3
✓ Branch 0 taken 280536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2939741 times.
3220277 switch(it)
1996 {
1997 case -2:
1998 {
1999 for(int32_t i=0; i<MAXLEVELS; i++)
2000 {
2001 if(game->lvlitems[i]&liTRIFORCE)
2002 {
2003 return true;
2004 }
2005 }
2006
2007 return false;
2008 }
2009
2010 case -1:
2011 2939741 return (game->lvlitems[dlevel]&liTRIFORCE);
2012
2013 default:
2014
2/4
✓ Branch 0 taken 280536 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 280536 times.
280536 if(it>=0&&it<MAXLEVELS)
2015 {
2016 280536 return (game->lvlitems[it]&liTRIFORCE);
2017 }
2018
2019 break;
2020 }
2021
2022 return 0;
2023 }
2024
2025 case itype_map: //it: -2=any, -1=current level, other=that level
2026 {
2027
2/3
✓ Branch 0 taken 402420 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15767794 times.
16170214 switch(it)
2028 {
2029 case -2:
2030 {
2031 for(int32_t i=0; i<MAXLEVELS; i++)
2032 {
2033 if(game->lvlitems[i]&liMAP)
2034 {
2035 return true;
2036 }
2037 }
2038
2039 return false;
2040 }
2041
2042 case -1:
2043 15767794 return (game->lvlitems[dlevel]&liMAP)!=0;
2044
2045 default:
2046
2/4
✓ Branch 0 taken 402420 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 402420 times.
402420 if(it>=0&&it<MAXLEVELS)
2047 {
2048 402420 return (game->lvlitems[it]&liMAP)!=0;
2049 }
2050
2051 break;
2052 }
2053
2054 return 0;
2055 }
2056
2057 case itype_compass: //it: -2=any, -1=current level, other=that level
2058 {
2059
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 5493498 times.
5493498 switch(it)
2060 {
2061 case -2:
2062 {
2063 for(int32_t i=0; i<MAXLEVELS; i++)
2064 {
2065 if(game->lvlitems[i]&liCOMPASS)
2066 {
2067 return true;
2068 }
2069 }
2070
2071 return false;
2072 }
2073
2074 case -1:
2075 5493498 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
2076
2077 default:
2078 if(it>=0&&it<MAXLEVELS)
2079 {
2080 return (game->lvlitems[it]&liCOMPASS)!=0;
2081 }
2082
2083 break;
2084 }
2085 return 0;
2086 }
2087
2088 case itype_bosskey: //it: -2=any, -1=current level, other=that level
2089 {
2090
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 115687 times.
115687 switch(it)
2091 {
2092 case -2:
2093 {
2094 for(int32_t i=0; i<MAXLEVELS; i++)
2095 {
2096 if(game->lvlitems[i]&liBOSSKEY)
2097 {
2098 return true;
2099 }
2100 }
2101
2102 return false;
2103 }
2104
2105 case -1:
2106 115687 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
2107
2108 default:
2109 if(it>=0&&it<MAXLEVELS)
2110 {
2111 return (game->lvlitems[it]&liBOSSKEY)?1:0;
2112 }
2113 break;
2114 }
2115 return 0;
2116 }
2117
2118 default:
2119 //it=(1<<(it-1));
2120 /*if (item_type>=itype_max)
2121 {
2122 enter_sys_pal();
2123 jwin_alert("Error","has_item exception",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2124 exit_sys_pal();
2125
2126 return false;
2127 }*/
2128 int32_t itemid = getItemID(itemsbuf, item_type, it);
2129
2130 if(itemid == -1)
2131 return false;
2132
2133 return game->get_item(itemid);
2134 }
2135 25026143 }
2136
2137
2138 51803521 int32_t current_item(int32_t item_type, bool checkenabled) //item currently being used
2139 {
2140
9/9
✓ Branch 0 taken 26467 times.
✓ Branch 1 taken 51591785 times.
✓ Branch 2 taken 26467 times.
✓ Branch 3 taken 26467 times.
✓ Branch 4 taken 26467 times.
✓ Branch 5 taken 26467 times.
✓ Branch 6 taken 26467 times.
✓ Branch 7 taken 26467 times.
✓ Branch 8 taken 26467 times.
51803521 switch(item_type)
2141 {
2142 case itype_clock:
2143 {
2144 26467 int32_t maxid = getHighestLevelOfFamily(game, itemsbuf, item_type, checkenabled);
2145
2146
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 26467 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
26467 if(maxid != -1 && (itemsbuf[maxid].flags & ITEM_FLAG1)) //Active clock
2147 return itemsbuf[maxid].fam_type;
2148
2149 26467 return has_item(itype_clock,1) ? 1 : 0;
2150 }
2151
2152 case itype_key:
2153 26467 return game->get_keys();
2154
2155 case itype_lkey:
2156 26467 return game->lvlkeys[get_dlevel()];
2157
2158 case itype_magiccontainer:
2159 26467 return game->get_maxmagic()/game->get_mp_per_block();
2160
2161 case itype_triforcepiece:
2162 {
2163 26467 int32_t count=0;
2164
2165
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<MAXLEVELS; i++)
2166 {
2167 13551104 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
2168 13551104 }
2169
2170 26467 return count;
2171 }
2172
2173 case itype_map:
2174 {
2175 26467 int32_t count=0;
2176
2177
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<MAXLEVELS; i++)
2178 {
2179 13551104 count+=(game->lvlitems[i]&liMAP)?1:0;
2180 13551104 }
2181
2182 26467 return count;
2183 }
2184
2185 case itype_compass:
2186 {
2187 26467 int32_t count=0;
2188
2189
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<MAXLEVELS; i++)
2190 {
2191 13551104 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
2192 13551104 }
2193
2194 26467 return count;
2195 }
2196
2197 case itype_bosskey:
2198 {
2199 26467 int32_t count=0;
2200
2201
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<MAXLEVELS; i++)
2202 {
2203 13551104 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2204 13551104 }
2205
2206 26467 return count;
2207 }
2208
2209 default:
2210 51591785 int32_t maxid = getHighestLevelOfFamily(game, itemsbuf, item_type, checkenabled);
2211
2212
2/2
✓ Branch 0 taken 9875888 times.
✓ Branch 1 taken 41715897 times.
51591785 if(maxid == -1)
2213 41715897 return 0;
2214
2215 9875888 return itemsbuf[maxid].fam_type;
2216 }
2217 51803521 }
2218
2219 44185160 int32_t current_item(int32_t item_type) //item currently being used
2220 {
2221 44185160 return current_item(item_type, true);
2222 }
2223
2224 117 std::map<int32_t, int32_t> itemcache;
2225 117 std::map<int32_t, int32_t> itemcache_cost;
2226
2227 void removeFromItemCache(int32_t itemclass)
2228 {
2229 itemcache.erase(itemclass);
2230 itemcache_cost.erase(itemclass);
2231 cache_tile_mod_clear();
2232 }
2233
2234 5861589 void flushItemCache(bool justcost)
2235 {
2236 5861589 itemcache_cost.clear();
2237
2/2
✓ Branch 0 taken 5831552 times.
✓ Branch 1 taken 30037 times.
5861589 if(!justcost)
2238 30037 itemcache.clear();
2239
2/2
✓ Branch 0 taken 5831120 times.
✓ Branch 1 taken 432 times.
5831552 else if(replay_version_check(0,19))
2240 5831120 return;
2241
2242 30469 cache_tile_mod_clear();
2243
2244 //also fix the active subscreen if items were deleted -DD
2245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30469 times.
30469 if(game != NULL)
2246 {
2247 30469 verifyBothWeapons();
2248 30469 refresh_subscr_items();
2249 30469 }
2250 5861589 }
2251
2252 // This is used often, so it should be as direct as possible.
2253 237709450 int32_t _c_item_id_internal(int32_t itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2254 {
2255 237709450 bool use_cost_cache = replay_version_check(19);
2256
2/2
✓ Branch 0 taken 196300092 times.
✓ Branch 1 taken 41409358 times.
237709450 if(jinx_check)
2257 {
2258
4/4
✓ Branch 0 taken 39648346 times.
✓ Branch 1 taken 1761012 times.
✓ Branch 2 taken 566272 times.
✓ Branch 3 taken 39082074 times.
41409358 if(!(HeroSwordClk() || HeroItemClk()))
2259 39082074 jinx_check = false; //not jinxed
2260 41409358 }
2261
2/2
✓ Branch 0 taken 113585 times.
✓ Branch 1 taken 237595865 times.
237709450 if(!Hero.BunnyClock())
2262 237595865 check_bunny = false; //not bunnied
2263
2/2
✓ Branch 0 taken 214185530 times.
✓ Branch 1 taken 23523920 times.
237709450 if(itemtype == itype_ring) checkmagic = true;
2264
4/4
✓ Branch 0 taken 235382166 times.
✓ Branch 1 taken 2327284 times.
✓ Branch 2 taken 211844883 times.
✓ Branch 3 taken 23242659 times.
472796992 if (!jinx_check && !check_bunny
2265
3/4
✓ Branch 0 taken 235382166 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 235087542 times.
✓ Branch 3 taken 294624 times.
235382166 && (use_cost_cache || itemtype != itype_ring))
2266 {
2267
4/4
✓ Branch 0 taken 171788425 times.
✓ Branch 1 taken 40351082 times.
✓ Branch 2 taken 171626759 times.
✓ Branch 3 taken 161666 times.
212139507 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2268 212139507 auto res = cache.find(itemtype);
2269
2270
2/2
✓ Branch 0 taken 196811351 times.
✓ Branch 1 taken 15328156 times.
212139507 if(res != cache.end())
2271 196811351 return res->second;
2272 15328156 }
2273
2274 40898099 int32_t result = -1;
2275 40898099 int32_t highestlevel = -1;
2276
2277
2/2
✓ Branch 0 taken 10469913344 times.
✓ Branch 1 taken 40898099 times.
10510811443 for(int32_t i=0; i<MAXITEMS; i++)
2278 {
2279
5/6
✓ Branch 0 taken 740217074 times.
✓ Branch 1 taken 9729696270 times.
✓ Branch 2 taken 16232085 times.
✓ Branch 3 taken 723984989 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 16232085 times.
10469913344 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2280 {
2281
4/4
✓ Branch 0 taken 15725221 times.
✓ Branch 1 taken 506864 times.
✓ Branch 2 taken 8694 times.
✓ Branch 3 taken 15716527 times.
16232085 if(checkmagic && itemtype != itype_magicring)
2282
2/2
✓ Branch 0 taken 15716369 times.
✓ Branch 1 taken 158 times.
15716527 if(!checkmagiccost(i))
2283 158 continue;
2284
6/6
✓ Branch 0 taken 14671645 times.
✓ Branch 1 taken 1560282 times.
✓ Branch 2 taken 106359 times.
✓ Branch 3 taken 1453923 times.
✓ Branch 4 taken 863941 times.
✓ Branch 5 taken 696341 times.
16231927 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 696341 times.
696341 if(!(itemsbuf[i].flags & ITEM_JINX_IMMUNE))
2286 696341 continue;
2287
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15535586 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15535586 if(check_bunny && !checkbunny(i))
2288 continue;
2289
2290
2/2
✓ Branch 0 taken 153893 times.
✓ Branch 1 taken 15381693 times.
15535586 if(itemsbuf[i].fam_type >= highestlevel)
2291 {
2292 15381693 highestlevel = itemsbuf[i].fam_type;
2293 15381693 result=i;
2294 15381693 }
2295 15535586 }
2296 10469216845 }
2297
2298
3/4
✓ Branch 0 taken 38570815 times.
✓ Branch 1 taken 2327284 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 38570815 times.
40898099 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2299 {
2300
2/2
✓ Branch 0 taken 4460 times.
✓ Branch 1 taken 38566355 times.
38570815 if (use_cost_cache)
2301 {
2302
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 2192 times.
4460 if (!checkmagic)
2303 2192 itemcache[itemtype] = result;
2304
5/6
✓ Branch 0 taken 2192 times.
✓ Branch 1 taken 2268 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2188 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4460 if (checkmagic || result < 0 || checkmagiccost(result))
2305 4460 itemcache_cost[itemtype] = result;
2306 4460 }
2307 else
2308 {
2309 38566355 itemcache[itemtype] = result;
2310 }
2311 38570815 }
2312 40898099 return result;
2313 237709450 }
2314
2315 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2316 235826379 int32_t current_item_id(int32_t itype, bool checkmagic, bool jinx_check, bool check_bunny)
2317 {
2318
2/4
✓ Branch 0 taken 235826379 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 235826379 times.
235826379 if(itype < 0 || itype >= itype_max) return -1;
2319
1/2
✓ Branch 0 taken 235826379 times.
✗ Branch 1 not taken.
235826379 if(game->OverrideItems[itype] > -2)
2320 {
2321 auto ovid = game->OverrideItems[itype];
2322 if(ovid < 0 || ovid >= MAXITEMS)
2323 return -1;
2324 if(itemsbuf[ovid].family == itype)
2325 {
2326 if(itype == itype_magicring)
2327 checkmagic = false;
2328 else if(itype == itype_ring)
2329 checkmagic = true;
2330
2331 if(checkmagic && !checkmagiccost(ovid))
2332 return -1;
2333 if(jinx_check && !(itemsbuf[ovid].flags & ITEM_JINX_IMMUNE)
2334 && (usesSwordJinx(ovid) ? HeroSwordClk() : HeroItemClk()))
2335 return -1;
2336 return ovid;
2337 }
2338 }
2339 235826379 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2340
2/2
✓ Branch 0 taken 39526287 times.
✓ Branch 1 taken 196300092 times.
235826379 if(!jinx_check) //If not already a jinx-immune-only check...
2341 {
2342 //And the player IS jinxed...
2343
4/4
✓ Branch 0 taken 194882057 times.
✓ Branch 1 taken 1418035 times.
✓ Branch 2 taken 465036 times.
✓ Branch 3 taken 194417021 times.
196300092 if(HeroSwordClk() || HeroItemClk())
2344 {
2345 //Then do a jinx-immune-only check here
2346 1883071 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2347 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2348 //Should NOT need a compat rule, as this should always return -1 in old quests.
2349
2/2
✓ Branch 0 taken 523190 times.
✓ Branch 1 taken 1359881 times.
1883071 if(ret2 > -1) return ret2;
2350 1359881 }
2351 195776902 }
2352 235303189 return ret;
2353 235826379 }
2354
2355 19471445 int32_t current_item_power(int32_t itemtype)
2356 {
2357 19471445 int32_t result = current_item_id(itemtype,true);
2358
2/2
✓ Branch 0 taken 14106681 times.
✓ Branch 1 taken 5364764 times.
19471445 return (result<0) ? 0 : itemsbuf[result].power;
2359 }
2360
2361 11 int32_t heart_container_id()
2362 {
2363
1/2
✓ Branch 0 taken 319 times.
✗ Branch 1 not taken.
319 for(int32_t i=0; i<MAXITEMS; i++)
2364 {
2365
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 308 times.
319 if(itemsbuf[i].family == itype_heartcontainer)
2366 {
2367 11 return i;
2368 }
2369 308 }
2370 return -1;
2371 11 }
2372
2373 struct tilemod_cache_state_t
2374 {
2375
6/6
✓ Branch 0 taken 26147 times.
✓ Branch 1 taken 6027753 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6027751 times.
✓ Branch 4 taken 318 times.
✓ Branch 5 taken 6027433 times.
12081653 bool operator==(const tilemod_cache_state_t&) const = default;
2376
2377 bool valid;
2378 bool bunny_clock;
2379 bool superman;
2380 int shield;
2381 };
2382 tilemod_cache_state_t tilemod_cache_state;
2383 int32_t tilemod_cache_value;
2384
2385 31001 void cache_tile_mod_clear()
2386 {
2387 31001 tilemod_cache_state = {false};
2388 31001 }
2389
2390 6053900 int32_t item_tile_mod()
2391 {
2392 24215600 tilemod_cache_state_t state = {
2393 .valid = true,
2394 6053900 .bunny_clock = Hero.BunnyClock() != 0,
2395 6053900 .superman = Hero.superman,
2396 6053900 .shield = Hero.active_shield_id,
2397 };
2398
2/2
✓ Branch 0 taken 6027433 times.
✓ Branch 1 taken 26467 times.
6053900 if (tilemod_cache_state == state)
2399 6027433 return tilemod_cache_value;
2400
2401 26467 int32_t tile=0;
2402 26467 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2403
3/4
✓ Branch 0 taken 26467 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21489 times.
✓ Branch 3 taken 4978 times.
26467 if(check_bombcost || game->get_bombs())
2404 {
2405 21489 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2406
3/4
✓ Branch 0 taken 20340 times.
✓ Branch 1 taken 1149 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20340 times.
21489 if(itemid > -1 && checkbunny(itemid))
2407 20340 tile+=itemsbuf[itemid].ltm;
2408 21489 }
2409
2410
3/4
✓ Branch 0 taken 26467 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6765 times.
✓ Branch 3 taken 19702 times.
26467 if(check_bombcost || game->get_sbombs())
2411 {
2412 6765 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2413
3/4
✓ Branch 0 taken 6759 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6759 times.
6765 if(itemid > -1 && checkbunny(itemid))
2414 6759 tile+=itemsbuf[itemid].ltm;
2415 6765 }
2416
2417
2/2
✓ Branch 0 taken 25610 times.
✓ Branch 1 taken 857 times.
26467 if(current_item(itype_clock))
2418 {
2419 857 int32_t itemid =
2420
1/2
✓ Branch 0 taken 857 times.
✗ Branch 1 not taken.
857 get_qr(qr_HARDCODED_LITEM_LTMS)
2421 ? iClock
2422 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2423
2/4
✓ Branch 0 taken 857 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 857 times.
857 if(itemid > -1 && checkbunny(itemid))
2424 857 tile+=itemsbuf[itemid].ltm;
2425 857 }
2426
2427
2/2
✓ Branch 0 taken 20192 times.
✓ Branch 1 taken 6275 times.
26467 if(current_item(itype_key))
2428 {
2429 6275 int32_t itemid =
2430
1/2
✓ Branch 0 taken 6275 times.
✗ Branch 1 not taken.
6275 get_qr(qr_HARDCODED_LITEM_LTMS)
2431 ? iKey
2432 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2433
2/4
✓ Branch 0 taken 6275 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6275 times.
6275 if(itemid > -1 && checkbunny(itemid))
2434 6275 tile+=itemsbuf[itemid].ltm;
2435 6275 }
2436
2437
2/2
✓ Branch 0 taken 24989 times.
✓ Branch 1 taken 1478 times.
26467 if(current_item(itype_lkey))
2438 {
2439 1478 int32_t itemid =
2440
2/2
✓ Branch 0 taken 1472 times.
✓ Branch 1 taken 6 times.
1478 get_qr(qr_HARDCODED_LITEM_LTMS)
2441 ? iLevelKey
2442 6 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2443
2/4
✓ Branch 0 taken 1478 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1478 times.
1478 if(itemid > -1 && checkbunny(itemid))
2444 1478 tile+=itemsbuf[itemid].ltm;
2445 1478 }
2446
2447
2/2
✓ Branch 0 taken 5912 times.
✓ Branch 1 taken 20555 times.
26467 if(current_item(itype_map))
2448 {
2449 20555 int32_t itemid =
2450
2/2
✓ Branch 0 taken 20553 times.
✓ Branch 1 taken 2 times.
20555 get_qr(qr_HARDCODED_LITEM_LTMS)
2451 ? iMap
2452 2 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2453
2/4
✓ Branch 0 taken 20555 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20555 times.
20555 if(itemid > -1 && checkbunny(itemid))
2454 20555 tile+=itemsbuf[itemid].ltm;
2455 20555 }
2456
2457
2/2
✓ Branch 0 taken 5698 times.
✓ Branch 1 taken 20769 times.
26467 if(current_item(itype_compass))
2458 {
2459 20769 int32_t itemid =
2460
2/2
✓ Branch 0 taken 20368 times.
✓ Branch 1 taken 401 times.
20769 get_qr(qr_HARDCODED_LITEM_LTMS)
2461 ? iCompass
2462 401 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2463
2/4
✓ Branch 0 taken 20769 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20769 times.
20769 if(itemid > -1 && checkbunny(itemid))
2464 20769 tile+=itemsbuf[itemid].ltm;
2465 20769 }
2466
2467
2/2
✓ Branch 0 taken 15499 times.
✓ Branch 1 taken 10968 times.
26467 if(current_item(itype_bosskey))
2468 {
2469 10968 int32_t itemid =
2470
1/2
✓ Branch 0 taken 10968 times.
✗ Branch 1 not taken.
10968 get_qr(qr_HARDCODED_LITEM_LTMS)
2471 ? iBossKey
2472 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2473
2/4
✓ Branch 0 taken 10968 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10968 times.
10968 if(itemid > -1 && checkbunny(itemid))
2474 10968 tile+=itemsbuf[itemid].ltm;
2475 10968 }
2476
2477
2/2
✓ Branch 0 taken 13012 times.
✓ Branch 1 taken 13455 times.
26467 if(current_item(itype_magiccontainer))
2478 {
2479 13455 int32_t itemid =
2480
2/2
✓ Branch 0 taken 13001 times.
✓ Branch 1 taken 454 times.
13455 get_qr(qr_HARDCODED_LITEM_LTMS)
2481 ? iMagicC
2482 454 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2483
3/4
✓ Branch 0 taken 13455 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 13438 times.
13455 if(itemid > -1 && checkbunny(itemid))
2484 13438 tile+=itemsbuf[itemid].ltm;
2485 13455 }
2486
2487
2/2
✓ Branch 0 taken 7161 times.
✓ Branch 1 taken 19306 times.
26467 if(current_item(itype_triforcepiece))
2488 {
2489 19306 int32_t itemid =
2490
1/2
✓ Branch 0 taken 19306 times.
✗ Branch 1 not taken.
19306 get_qr(qr_HARDCODED_LITEM_LTMS)
2491 ? iTriforce
2492 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2493
2/4
✓ Branch 0 taken 19306 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19306 times.
19306 if(itemid > -1 && checkbunny(itemid))
2494 19306 tile+=itemsbuf[itemid].ltm;
2495 19306 }
2496
2497
2/2
✓ Branch 0 taken 13551104 times.
✓ Branch 1 taken 26467 times.
13577571 for(int32_t i=0; i<itype_max; i++)
2498 {
2499
2/2
✓ Branch 0 taken 13294592 times.
✓ Branch 1 taken 256512 times.
13551104 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2500 {
2501
2/2
✓ Branch 0 taken 5010 times.
✓ Branch 1 taken 251502 times.
256512 switch(i)
2502 {
2503 case itype_bomb:
2504 case itype_sbomb:
2505 case itype_clock:
2506 case itype_key:
2507 case itype_lkey:
2508 case itype_map:
2509 case itype_compass:
2510 case itype_bosskey:
2511 case itype_magiccontainer:
2512 case itype_triforcepiece:
2513 5010 continue; //already handled
2514 }
2515 251502 }
2516 13546094 int32_t itemid = current_item_id(i,false);
2517
2/2
✓ Branch 0 taken 13519627 times.
✓ Branch 1 taken 26467 times.
13546094 if(i == itype_shield)
2518 26467 itemid = getCurrentShield(false);
2519
2520
4/4
✓ Branch 0 taken 353604 times.
✓ Branch 1 taken 13192490 times.
✓ Branch 2 taken 919 times.
✓ Branch 3 taken 352685 times.
13546094 if(itemid < 0 || !checkbunny(itemid))
2521 13193409 continue;
2522
2523 352685 itemdata const& itm = itemsbuf[itemid];
2524
2525
2/2
✓ Branch 0 taken 328767 times.
✓ Branch 1 taken 23918 times.
352685 switch(itm.family)
2526 {
2527 case itype_shield:
2528
1/2
✓ Branch 0 taken 23918 times.
✗ Branch 1 not taken.
23918 if(itm.flags & ITEM_FLAG9) //active shield
2529 {
2530 if(!usingActiveShield(itemid))
2531 {
2532 tile+=itm.misc6; //'Inactive PTM'
2533 continue;
2534 }
2535 }
2536 23918 break;
2537 }
2538
2539 352685 tile+=itm.ltm;
2540 352685 }
2541
2542 26467 tilemod_cache_value = tile;
2543 26467 tilemod_cache_state = state;
2544 26467 return tile;
2545 6053900 }
2546
2547 6053900 int32_t bunny_tile_mod()
2548 {
2549
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 6052030 times.
6053900 if(Hero.BunnyClock())
2550 {
2551 1870 return game->get_bunny_ltm();
2552 }
2553 6052030 return 0;
2554 6053900 }
2555
2556 // Hints are drawn on a separate layer to combo reveals.
2557 16332 void draw_lens_under(BITMAP *dest, bool layer)
2558 {
2559 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2560 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2561 //Lens flag 3: Don't show armos/chest/dive items
2562 //Lens flag 4: Show Raft Paths
2563 //Lens flag 5: Show Invisible Enemies
2564
4/4
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 15876 times.
✓ Branch 2 taken 7938 times.
✓ Branch 3 taken 7938 times.
16332 bool hints = (itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG1));
2565
2566 16332 int32_t strike_hint_table[11]=
2567 {
2568 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2569 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2570 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2571 };
2572
2573 // int32_t page = tmpscr->cpage;
2574 {
2575 16332 int32_t blink_rate=flash_reduction_enabled()?6:1;
2576 // int32_t temptimer=0;
2577 16332 int32_t tempitem, tempweapon=0;
2578 16332 strike_hint=strike_hint_table[strike_hint_counter];
2579
2580
2/2
✓ Branch 0 taken 15842 times.
✓ Branch 1 taken 490 times.
16332 if(strike_hint_timer>32)
2581 {
2582 490 strike_hint_timer=0;
2583 490 strike_hint_counter=((strike_hint_counter+1)%11);
2584 490 }
2585
2586 16332 ++strike_hint_timer;
2587
2588
2/2
✓ Branch 0 taken 2874432 times.
✓ Branch 1 taken 16332 times.
2890764 for(int32_t i=0; i<176; i++)
2589 {
2590 2874432 int32_t x = (i & 15) << 4;
2591 2874432 int32_t y = (i & 0xF0) + playing_field_offset;
2592 2874432 int32_t tempitemx=-16, tempitemy=-16;
2593 2874432 int32_t tempweaponx=-16, tempweapony=-16;
2594
2595
2/2
✓ Branch 0 taken 5748864 times.
✓ Branch 1 taken 2874432 times.
8623296 for(int32_t iter=0; iter<2; ++iter)
2596 {
2597 5748864 int32_t checkflag=0;
2598
2599
2/2
✓ Branch 0 taken 2874432 times.
✓ Branch 1 taken 2874432 times.
5748864 if(iter==0)
2600 {
2601 2874432 checkflag=combobuf[tmpscr->data[i]].flag;
2602 2874432 }
2603 else
2604 {
2605 2874432 checkflag=tmpscr->sflag[i];
2606 }
2607
2608
2/2
✓ Branch 0 taken 5747766 times.
✓ Branch 1 taken 1098 times.
5748864 if(checkflag==mfSTRIKE)
2609 {
2610
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2611 {
2612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSTRIKE],tmpscr->secretcset[sSTRIKE]);
2613 906 }
2614 else
2615 {
2616 192 checkflag = strike_hint;
2617 }
2618 1098 }
2619
2620
20/36
✓ Branch 0 taken 5706470 times.
✓ Branch 1 taken 3148 times.
✓ Branch 2 taken 3618 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2064 times.
✓ Branch 5 taken 28640 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 33 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 5 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
5748864 switch(checkflag)
2621 {
2622 case 0:
2623 case mfZELDA:
2624 case mfPUSHED:
2625 case mfENEMY0:
2626 case mfENEMY1:
2627 case mfENEMY2:
2628 case mfENEMY3:
2629 case mfENEMY4:
2630 case mfENEMY5:
2631 case mfENEMY6:
2632 case mfENEMY7:
2633 case mfENEMY8:
2634 case mfENEMY9:
2635 case mfSINGLE:
2636 case mfSINGLE16:
2637 case mfNOENEMY:
2638 case mfTRAP_H:
2639 case mfTRAP_V:
2640 case mfTRAP_4:
2641 case mfTRAP_LR:
2642 case mfTRAP_UD:
2643 case mfNOGROUNDENEMY:
2644 case mfNOBLOCKS:
2645 case mfSCRIPT1:
2646 case mfSCRIPT2:
2647 case mfSCRIPT3:
2648 case mfSCRIPT4:
2649 case mfSCRIPT5:
2650 case mfSCRIPT6:
2651 case mfSCRIPT7:
2652 case mfSCRIPT8:
2653 case mfSCRIPT9:
2654 case mfSCRIPT10:
2655 case mfSCRIPT11:
2656 case mfSCRIPT12:
2657 case mfSCRIPT13:
2658 case mfSCRIPT14:
2659 case mfSCRIPT15:
2660 case mfSCRIPT16:
2661 case mfSCRIPT17:
2662 case mfSCRIPT18:
2663 case mfSCRIPT19:
2664 case mfSCRIPT20:
2665 case mfPITHOLE:
2666 case mfPITFALLFLOOR:
2667 case mfLAVA:
2668 case mfICE:
2669 case mfICEDAMAGE:
2670 case mfDAMAGE1:
2671 case mfDAMAGE2:
2672 case mfDAMAGE4:
2673 case mfDAMAGE8:
2674 case mfDAMAGE16:
2675 case mfDAMAGE32:
2676 case mfFREEZEALL:
2677 case mfFREZEALLANSFFCS:
2678 case mfFREEZEFFCSOLY:
2679 case mfSCRITPTW1TRIG:
2680 case mfSCRITPTW2TRIG:
2681 case mfSCRITPTW3TRIG:
2682 case mfSCRITPTW4TRIG:
2683 case mfSCRITPTW5TRIG:
2684 case mfSCRITPTW6TRIG:
2685 case mfSCRITPTW7TRIG:
2686 case mfSCRITPTW8TRIG:
2687 case mfSCRITPTW9TRIG:
2688 case mfSCRITPTW10TRIG:
2689 case mfTROWEL:
2690 case mfTROWELNEXT:
2691 case mfTROWELSPECIALITEM:
2692 case mfSLASHPOT:
2693 case mfLIFTPOT:
2694 case mfLIFTORSLASH:
2695 case mfLIFTROCK:
2696 case mfLIFTROCKHEAVY:
2697 case mfDROPITEM:
2698 case mfSPECIALITEM:
2699 case mfDROPKEY:
2700 case mfDROPLKEY:
2701 case mfDROPCOMPASS:
2702 case mfDROPMAP:
2703 case mfDROPBOSSKEY:
2704 case mfSPAWNNPC:
2705 case mfSWITCHHOOK:
2706 case mfSIDEVIEWLADDER:
2707 case mfSIDEVIEWPLATFORM:
2708 case mfNOENEMYSPAWN:
2709 case mfENEMYALL:
2710 case mfNOMIRROR:
2711 case mfUNSAFEGROUND:
2712 case mf168:
2713 case mf169:
2714 case mf170:
2715 case mf171:
2716 case mf172:
2717 case mf173:
2718 case mf174:
2719 case mf175:
2720 case mf176:
2721 case mf177:
2722 case mf178:
2723 case mf179:
2724 case mf180:
2725 case mf181:
2726 case mf182:
2727 case mf183:
2728 case mf184:
2729 case mf185:
2730 case mf186:
2731 case mf187:
2732 case mf188:
2733 case mf189:
2734 case mf190:
2735 case mf191:
2736 case mf192:
2737 case mf193:
2738 case mf194:
2739 case mf195:
2740 case mf196:
2741 case mf197:
2742 case mf198:
2743 case mf199:
2744 case mf200:
2745 case mf201:
2746 case mf202:
2747 case mf203:
2748 case mf204:
2749 case mf205:
2750 case mf206:
2751 case mf207:
2752 case mf208:
2753 case mf209:
2754 case mf210:
2755 case mf211:
2756 case mf212:
2757 case mf213:
2758 case mf214:
2759 case mf215:
2760 case mf216:
2761 case mf217:
2762 case mf218:
2763 case mf219:
2764 case mf220:
2765 case mf221:
2766 case mf222:
2767 case mf223:
2768 case mf224:
2769 case mf225:
2770 case mf226:
2771 case mf227:
2772 case mf228:
2773 case mf229:
2774 case mf230:
2775 case mf231:
2776 case mf232:
2777 case mf233:
2778 case mf234:
2779 case mf235:
2780 case mf236:
2781 case mf237:
2782 case mf238:
2783 case mf239:
2784 case mf240:
2785 case mf241:
2786 case mf242:
2787 case mf243:
2788 case mf244:
2789 case mf245:
2790 case mf246:
2791 case mf247:
2792 case mf248:
2793 case mf249:
2794 case mf250:
2795 case mf251:
2796 case mf252:
2797 case mf253:
2798 case mf254:
2799 case mfEXTENDED:
2800 5706470 break;
2801
2802 case mfPUSHUD:
2803 case mfPUSHLR:
2804 case mfPUSH4:
2805 case mfPUSHU:
2806 case mfPUSHD:
2807 case mfPUSHL:
2808 case mfPUSHR:
2809 case mfPUSHUDNS:
2810 case mfPUSHLRNS:
2811 case mfPUSH4NS:
2812 case mfPUSHUNS:
2813 case mfPUSHDNS:
2814 case mfPUSHLNS:
2815 case mfPUSHRNS:
2816 case mfPUSHUDINS:
2817 case mfPUSHLRINS:
2818 case mfPUSH4INS:
2819 case mfPUSHUINS:
2820 case mfPUSHDINS:
2821 case mfPUSHLINS:
2822 case mfPUSHRINS:
2823
3/4
✓ Branch 0 taken 1829 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1829 times.
3148 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2824
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1829 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1829 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1829 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2825 {
2826 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->undercombo,tmpscr->undercset);
2827 }
2828
2829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3148 times.
3148 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2830
3/6
✓ Branch 0 taken 2438 times.
✓ Branch 1 taken 710 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 710 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3148 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2831 {
2832
2/2
✓ Branch 0 taken 1406 times.
✓ Branch 1 taken 1032 times.
2438 if(hints)
2833 {
2834
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch(combobuf[tmpscr->data[i]].type)
2835 {
2836 case cPUSH_HEAVY:
2837 case cPUSH_HW:
2838 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2839 72 tempitemx=x, tempitemy=y;
2840
2841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(tempitem>-1)
2842 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2843
2844 72 break;
2845
2846 case cPUSH_HEAVY2:
2847 case cPUSH_HW2:
2848 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2849 63 tempitemx=x, tempitemy=y;
2850
2851
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
63 if(tempitem>-1)
2852 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2853
2854 63 break;
2855 }
2856 1032 }
2857 2438 }
2858
2859 3148 break;
2860
2861 case mfWHISTLE:
2862
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2863 {
2864 tempitem=getItemID(itemsbuf,itype_whistle,1);
2865
2866 if(tempitem<0) break;
2867
2868 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2869 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2870 {
2871 tempitemx=x;
2872 tempitemy=y;
2873 }
2874
2875 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2876 }
2877
2878 2418 break;
2879
2880 //Why is this here?
2881 case mfFAIRY:
2882 case mfMAGICFAIRY:
2883 case mfALLFAIRY:
2884 if(hints)
2885 {
2886 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2887
2888 if(tempitem < 0) break;
2889
2890 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2891 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2892 {
2893 tempitemx=x;
2894 tempitemy=y;
2895 }
2896
2897 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2898 }
2899
2900 break;
2901
2902 case mfANYFIRE:
2903
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2904 {
2905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBCANDLE],tmpscr->secretcset[sBCANDLE]);
2906 252 }
2907 else
2908 {
2909 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2910
2911
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2912
2913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2914
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2915 {
2916 189 tempitemx=x;
2917 189 tempitemy=y;
2918 189 }
2919
2920 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2921 }
2922
2923 504 break;
2924
2925 case mfSTRONGFIRE:
2926 if(!hints)
2927 {
2928 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sRCANDLE],tmpscr->secretcset[sRCANDLE]);
2929 }
2930 else
2931 {
2932 tempitem=getItemID(itemsbuf,itype_candle,2);
2933
2934 if(tempitem<0) break;
2935
2936 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2937 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2938 {
2939 tempitemx=x;
2940 tempitemy=y;
2941 }
2942
2943 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2944 }
2945
2946 break;
2947
2948 case mfMAGICFIRE:
2949 if(!hints)
2950 {
2951 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDFIRE],tmpscr->secretcset[sWANDFIRE]);
2952 }
2953 else
2954 {
2955 tempitem=getItemID(itemsbuf,itype_wand,1);
2956
2957 if(tempitem<0) break;
2958
2959 tempweapon=wFire;
2960
2961 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2962 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2963 {
2964 tempitemx=x;
2965 tempitemy=y;
2966 }
2967 else
2968 {
2969 tempweaponx=x;
2970 tempweapony=y;
2971 }
2972
2973 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2974 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2975 }
2976
2977 break;
2978
2979 case mfDIVINEFIRE:
2980 if(!hints)
2981 {
2982 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sDIVINEFIRE],tmpscr->secretcset[sDIVINEFIRE]);
2983 }
2984 else
2985 {
2986 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2987
2988 if(tempitem<0) break;
2989
2990 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2991 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2992 {
2993 tempitemx=x;
2994 tempitemy=y;
2995 }
2996
2997 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2998 }
2999
3000 break;
3001
3002 case mfARROW:
3003
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
3004 {
3005
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sARROW],tmpscr->secretcset[sARROW]);
3006 732 }
3007 else
3008 {
3009 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
3010
3011
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
3012
3013
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3014
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3015 {
3016 61 tempitemx=x;
3017 61 tempitemy=y;
3018 61 }
3019
3020 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3021 }
3022
3023 814 break;
3024
3025 case mfSARROW:
3026 if(!hints)
3027 {
3028 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSARROW],tmpscr->secretcset[sSARROW]);
3029 }
3030 else
3031 {
3032 tempitem=getItemID(itemsbuf,itype_arrow,2);
3033
3034 if(tempitem<0) break;
3035
3036 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3037 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3038 {
3039 tempitemx=x;
3040 tempitemy=y;
3041 }
3042
3043 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3044 }
3045
3046 break;
3047
3048 case mfGARROW:
3049 if(!hints)
3050 {
3051 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sGARROW],tmpscr->secretcset[sGARROW]);
3052 }
3053 else
3054 {
3055 tempitem=getItemID(itemsbuf,itype_arrow,3);
3056
3057 if(tempitem<0) break;
3058
3059 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3060 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3061 {
3062 tempitemx=x;
3063 tempitemy=y;
3064 }
3065
3066 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3067 }
3068
3069 break;
3070
3071 case mfBOMB:
3072
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 16 times.
33 if(!hints)
3073 {
3074
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBOMB],tmpscr->secretcset[sBOMB]);
3075 16 }
3076 else
3077 {
3078 //tempitem=getItemID(itemsbuf,itype_bomb,1);
3079 17 tempweapon = wLitBomb;
3080
3081 //if (tempitem<0) break;
3082
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3083
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3084 {
3085 12 tempweaponx=x;
3086 12 tempweapony=y;
3087 12 }
3088
3089 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3090 }
3091
3092 33 break;
3093
3094 case mfSBOMB:
3095
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
3096 {
3097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSBOMB],tmpscr->secretcset[sSBOMB]);
3098 48 }
3099 else
3100 {
3101 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
3102 //if (tempitem<0) break;
3103 48 tempweapon = wLitSBomb;
3104
3105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3106
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3107 {
3108 36 tempweaponx=x;
3109 36 tempweapony=y;
3110 36 }
3111
3112 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3113 }
3114
3115 96 break;
3116
3117 case mfARMOS_SECRET:
3118
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
3119 {
3120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3121 12 }
3122 24 break;
3123
3124 case mfBRANG:
3125
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(!hints)
3126 {
3127 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sBRANG],tmpscr->secretcset[sBRANG]);
3128 }
3129 else
3130 {
3131 5 tempitem=getItemID(itemsbuf,itype_brang,1);
3132
3133
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
3134
3135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3136
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3137 {
3138 4 tempitemx=x;
3139 4 tempitemy=y;
3140 4 }
3141
3142 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3143 }
3144
3145 5 break;
3146
3147 case mfMBRANG:
3148 if(!hints)
3149 {
3150 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMBRANG],tmpscr->secretcset[sMBRANG]);
3151 }
3152 else
3153 {
3154 tempitem=getItemID(itemsbuf,itype_brang,2);
3155
3156 if(tempitem<0) break;
3157
3158 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3159 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3160 {
3161 tempitemx=x;
3162 tempitemy=y;
3163 }
3164
3165 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3166 }
3167
3168 break;
3169
3170 case mfFBRANG:
3171 if(!hints)
3172 {
3173 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sFBRANG],tmpscr->secretcset[sFBRANG]);
3174 }
3175 else
3176 {
3177 tempitem=getItemID(itemsbuf,itype_brang,3);
3178
3179 if(tempitem<0) break;
3180
3181 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3182 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3183 {
3184 tempitemx=x;
3185 tempitemy=y;
3186 }
3187
3188 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3189 }
3190
3191 break;
3192
3193 case mfWANDMAGIC:
3194 if(!hints)
3195 {
3196 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWANDMAGIC],tmpscr->secretcset[sWANDMAGIC]);
3197 }
3198 else
3199 {
3200 tempitem=getItemID(itemsbuf,itype_wand,1);
3201
3202 if(tempitem<0) break;
3203
3204 tempweapon=itemsbuf[tempitem].wpn3;
3205
3206 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3207 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3208 {
3209 tempitemx=x;
3210 tempitemy=y;
3211 }
3212 else
3213 {
3214 tempweaponx=x;
3215 tempweapony=y;
3216 --lens_hint_weapon[wMagic][4];
3217
3218 if(lens_hint_weapon[wMagic][4]<-8)
3219 {
3220 lens_hint_weapon[wMagic][4]=8;
3221 }
3222 }
3223
3224 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3225 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3226 }
3227
3228 break;
3229
3230 case mfREFMAGIC:
3231
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3232 {
3233 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sREFMAGIC],tmpscr->secretcset[sREFMAGIC]);
3234 }
3235 else
3236 {
3237 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3238
3239
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3240
3241 16 tempweapon=ewMagic;
3242
3243
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3244
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3245 {
3246 13 tempitemx=x;
3247 13 tempitemy=y;
3248 13 }
3249 else
3250 {
3251 3 tempweaponx=x;
3252 3 tempweapony=y;
3253
3254
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3255 {
3256 1 --lens_hint_weapon[ewMagic][4];
3257 1 }
3258 else
3259 {
3260 2 ++lens_hint_weapon[ewMagic][4];
3261 }
3262
3263
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3264 {
3265 lens_hint_weapon[ewMagic][2]=up;
3266 }
3267
3268
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3269 {
3270 2 lens_hint_weapon[ewMagic][2]=down;
3271 2 }
3272 }
3273
3274 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3275 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3276 }
3277
3278 16 break;
3279
3280 case mfREFFIREBALL:
3281
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3282 {
3283 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sREFFIREBALL],tmpscr->secretcset[sREFFIREBALL]);
3284 }
3285 else
3286 {
3287 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3288
3289
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3290
3291 16 tempweapon=ewFireball;
3292
3293
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3294
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3295 {
3296 12 tempitemx=x;
3297 12 tempitemy=y;
3298 12 tempweaponx=x;
3299 12 tempweapony=y;
3300 12 ++lens_hint_weapon[ewFireball][3];
3301
3302
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3303 {
3304 1 lens_hint_weapon[ewFireball][3]=-8;
3305 1 lens_hint_weapon[ewFireball][4]=8;
3306 1 }
3307
3308
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3309 {
3310 8 ++lens_hint_weapon[ewFireball][4];
3311 8 }
3312 else
3313 {
3314 4 --lens_hint_weapon[ewFireball][4];
3315 }
3316 12 }
3317
3318 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3319 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3320 }
3321
3322 16 break;
3323
3324 case mfSWORD:
3325
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3326 {
3327 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORD],tmpscr->secretcset[sSWORD]);
3328 }
3329 else
3330 {
3331 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3332
3333
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3334
3335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3336
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3337 {
3338 5 tempitemx=x;
3339 5 tempitemy=y;
3340 5 }
3341
3342 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3343 }
3344
3345 7 break;
3346
3347 case mfWSWORD:
3348 if(!hints)
3349 {
3350 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORD],tmpscr->secretcset[sWSWORD]);
3351 }
3352 else
3353 {
3354 tempitem=getItemID(itemsbuf,itype_sword,2);
3355
3356 if(tempitem<0) break;
3357
3358 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3359 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3360 {
3361 tempitemx=x;
3362 tempitemy=y;
3363 }
3364
3365 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3366 }
3367
3368 break;
3369
3370 case mfMSWORD:
3371 if(!hints)
3372 {
3373 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORD],tmpscr->secretcset[sMSWORD]);
3374 }
3375 else
3376 {
3377 tempitem=getItemID(itemsbuf,itype_sword,3);
3378
3379 if(tempitem<0) break;
3380
3381 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3382 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3383 {
3384 tempitemx=x;
3385 tempitemy=y;
3386 }
3387
3388 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3389 }
3390
3391 break;
3392
3393 case mfXSWORD:
3394 if(!hints)
3395 {
3396 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORD],tmpscr->secretcset[sXSWORD]);
3397 }
3398 else
3399 {
3400 tempitem=getItemID(itemsbuf,itype_sword,4);
3401
3402 if(tempitem<0) break;
3403
3404 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3405 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3406 {
3407 tempitemx=x;
3408 tempitemy=y;
3409 }
3410
3411 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3412 }
3413
3414 break;
3415
3416 case mfSWORDBEAM:
3417
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3418 {
3419 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sSWORDBEAM],tmpscr->secretcset[sSWORDBEAM]);
3420 }
3421 else
3422 {
3423 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3424
3425
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3426
3427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3428
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3429 {
3430 11 tempitemx=x;
3431 11 tempitemy=y;
3432 11 }
3433
3434 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3435 }
3436
3437 16 break;
3438
3439 case mfWSWORDBEAM:
3440 if(!hints)
3441 {
3442 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWSWORDBEAM],tmpscr->secretcset[sWSWORDBEAM]);
3443 }
3444 else
3445 {
3446 tempitem=getItemID(itemsbuf,itype_sword,2);
3447
3448 if(tempitem<0) break;
3449
3450 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3451 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3452 {
3453 tempitemx=x;
3454 tempitemy=y;
3455 }
3456
3457 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3458 }
3459
3460 break;
3461
3462 case mfMSWORDBEAM:
3463 if(!hints)
3464 {
3465 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sMSWORDBEAM],tmpscr->secretcset[sMSWORDBEAM]);
3466 }
3467 else
3468 {
3469 tempitem=getItemID(itemsbuf,itype_sword,3);
3470
3471 if(tempitem<0) break;
3472
3473 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3474 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3475 {
3476 tempitemx=x;
3477 tempitemy=y;
3478 }
3479
3480 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3481 }
3482
3483 break;
3484
3485 case mfXSWORDBEAM:
3486 if(!hints)
3487 {
3488 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sXSWORDBEAM],tmpscr->secretcset[sXSWORDBEAM]);
3489 }
3490 else
3491 {
3492 tempitem=getItemID(itemsbuf,itype_sword,4);
3493
3494 if(tempitem<0) break;
3495
3496 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3497 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3498 {
3499 tempitemx=x;
3500 tempitemy=y;
3501 }
3502
3503 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3504 }
3505
3506 break;
3507
3508 case mfHOOKSHOT:
3509
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3510 {
3511 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sHOOKSHOT],tmpscr->secretcset[sHOOKSHOT]);
3512 }
3513 else
3514 {
3515 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3516
3517
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3518
3519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3520
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3521 {
3522 12 tempitemx=x;
3523 12 tempitemy=y;
3524 12 }
3525
3526 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3527 }
3528
3529 17 break;
3530
3531 case mfWAND:
3532
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3533 {
3534 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sWAND],tmpscr->secretcset[sWAND]);
3535 }
3536 else
3537 {
3538 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3539
3540
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3541
3542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3543
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3544 {
3545 28 tempitemx=x;
3546 28 tempitemy=y;
3547 28 }
3548
3549 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3550 }
3551
3552 35 break;
3553
3554 case mfHAMMER:
3555
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3556 {
3557 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))putcombo(dest,x,y,tmpscr->secretcombo[sHAMMER],tmpscr->secretcset[sHAMMER]);
3558 }
3559 else
3560 {
3561 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3562
3563
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3564
3565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3566
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3567 {
3568 13 tempitemx=x;
3569 13 tempitemy=y;
3570 13 }
3571
3572 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3573 }
3574
3575 17 break;
3576
3577 case mfARMOS_ITEM:
3578 case mfDIVE_ITEM:
3579
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2064 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2064 if((!getmapflag() || (tmpscr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG3))
3580 {
3581 2064 putitem2(dest,x,y,tmpscr->catchall, lens_hint_item[tmpscr->catchall][0], lens_hint_item[tmpscr->catchall][1], 0);
3582 2064 }
3583 2064 break;
3584
3585 case 16:
3586 case 17:
3587 case 18:
3588 case 19:
3589 case 20:
3590 case 21:
3591 case 22:
3592 case 23:
3593 case 24:
3594 case 25:
3595 case 26:
3596 case 27:
3597 case 28:
3598 case 29:
3599 case 30:
3600 case 31:
3601
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 2610 times.
3618 if(!hints)
3602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2610 times.
5220 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3603 2610 putcombo(dest,x,y,tmpscr->secretcombo[checkflag-16+4],tmpscr->secretcset[checkflag-16+4]);
3604
3605 3618 break;
3606 case mfSECRETSNEXT:
3607 if(!hints)
3608 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3609 putcombo(dest,x,y,tmpscr->data[i]+1,tmpscr->cset[i]);
3610
3611 break;
3612
3613 case mfSTRIKE:
3614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3615 {
3616 906 goto special;
3617 }
3618 else
3619 {
3620 break;
3621 }
3622
3623 28640 default: goto special;
3624
3625 special:
3626
8/8
✓ Branch 0 taken 14677 times.
✓ Branch 1 taken 14869 times.
✓ Branch 2 taken 473 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 441 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29546 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG4)))
3627 {
3628
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6549 times.
✓ Branch 2 taken 4913 times.
✓ Branch 3 taken 1636 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1636 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6549 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3629 {
3630 4913 rectfill(dest,x,y,x+15,y+15,WHITE);
3631 4913 }
3632 6549 }
3633
3634 29546 break;
3635 }
3636 5748864 }
3637 2874432 }
3638
3639
2/2
✓ Branch 0 taken 8166 times.
✓ Branch 1 taken 8166 times.
16332 if(layer)
3640 {
3641
2/2
✓ Branch 0 taken 7978 times.
✓ Branch 1 taken 188 times.
8166 if(tmpscr->door[0]==dWALK)
3642 188 rectfill(dest, 120, 16+playing_field_offset, 135, 31+playing_field_offset, WHITE);
3643
3644
2/2
✓ Branch 0 taken 7969 times.
✓ Branch 1 taken 197 times.
8166 if(tmpscr->door[1]==dWALK)
3645 197 rectfill(dest, 120, 144+playing_field_offset, 135, 159+playing_field_offset, WHITE);
3646
3647
2/2
✓ Branch 0 taken 8014 times.
✓ Branch 1 taken 152 times.
8166 if(tmpscr->door[2]==dWALK)
3648 152 rectfill(dest, 16, 80+playing_field_offset, 31, 95+playing_field_offset, WHITE);
3649
3650
2/2
✓ Branch 0 taken 7940 times.
✓ Branch 1 taken 226 times.
8166 if(tmpscr->door[3]==dWALK)
3651 226 rectfill(dest, 224, 80+playing_field_offset, 239, 95+playing_field_offset, WHITE);
3652
3653
2/2
✓ Branch 0 taken 8123 times.
✓ Branch 1 taken 43 times.
8166 if(tmpscr->door[0]==dBOMB)
3654 {
3655 43 showbombeddoor(dest, 0);
3656 43 }
3657
3658
2/2
✓ Branch 0 taken 8127 times.
✓ Branch 1 taken 39 times.
8166 if(tmpscr->door[1]==dBOMB)
3659 {
3660 39 showbombeddoor(dest, 1);
3661 39 }
3662
3663
1/2
✓ Branch 0 taken 8166 times.
✗ Branch 1 not taken.
8166 if(tmpscr->door[2]==dBOMB)
3664 {
3665 showbombeddoor(dest, 2);
3666 }
3667
3668
2/2
✓ Branch 0 taken 8129 times.
✓ Branch 1 taken 37 times.
8166 if(tmpscr->door[3]==dBOMB)
3669 {
3670 37 showbombeddoor(dest, 3);
3671 37 }
3672 8166 }
3673
3674
2/2
✓ Branch 0 taken 14298 times.
✓ Branch 1 taken 2034 times.
16332 if(tmpscr->stairx + tmpscr->stairy)
3675 {
3676
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if(!hints)
3677 {
3678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if(!(itemsbuf[Hero.getLastLensID()].flags & ITEM_FLAG2))
3679 1123 putcombo(dest,tmpscr->stairx,tmpscr->stairy+playing_field_offset,tmpscr->secretcombo[sSTAIRS],tmpscr->secretcset[sSTAIRS]);
3680 1123 }
3681 else
3682 {
3683
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(tmpscr->flags&fWHISTLE)
3684 {
3685 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3686 48 int32_t tempitemx=-16;
3687 48 int32_t tempitemy=-16;
3688
3689
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3690
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3691 {
3692 24 tempitemx=tmpscr->stairx;
3693 24 tempitemy=tmpscr->stairy+playing_field_offset;
3694 24 }
3695
3696 48 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3697 48 }
3698 }
3699 2034 }
3700 }
3701 16332 }
3702
3703 BITMAP *lens_scr_d; // The "d" is for "destructible"!
3704
3705 7997 void draw_lens_over()
3706 {
3707 // Oh, what the heck.
3708 static BITMAP *lens_scr = NULL;
3709 static int32_t last_width = -1;
3710 7997 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3711
3712 // Only redraw the circle if the size has changed
3713
2/2
✓ Branch 0 taken 7987 times.
✓ Branch 1 taken 10 times.
7997 if(width != last_width)
3714 {
3715
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(lens_scr == NULL)
3716 {
3717 10 lens_scr = create_bitmap_ex(8,2*288,2*(240-playing_field_offset));
3718 10 }
3719
3720 10 clear_to_color(lens_scr, BLACK);
3721 10 circlefill(lens_scr, 288, 240-playing_field_offset, width, 0);
3722 10 circle(lens_scr, 288, 240-playing_field_offset, width+2, 0);
3723 10 circle(lens_scr, 288, 240-playing_field_offset, width+5, 0);
3724 10 last_width=width;
3725 10 }
3726
3727 7997 masked_blit(lens_scr, framebuf, 288-(HeroX()+8), 240-playing_field_offset-(HeroY()+8), 0, playing_field_offset, 256, 168);
3728 7997 do_primitives(framebuf, SPLAYER_LENS_OVER, tmpscr, 0, playing_field_offset);
3729 7997 }
3730
3731 //----------------------------------------------------------------
3732
3733 31111 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3734 {
3735 //recreating a big bitmap every frame is highly sluggish.
3736
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 31108 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
31111 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3737 31111 clear_to_color(wavebuf, BLACK);
3738 31111 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,224-original_playing_field_offset);
3739
3740 int32_t ofs;
3741 // int32_t amplitude=8;
3742 // int32_t wavelength=4;
3743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31111 times.
31111 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3744
3/6
✓ Branch 0 taken 31111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31111 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 31111 times.
31111 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3745 31111 int32_t amp2=168;
3746
2/4
✓ Branch 0 taken 31111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31111 times.
31111 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3747 31111 int32_t i=frame%amp2;
3748
3749
2/2
✓ Branch 0 taken 5226648 times.
✓ Branch 1 taken 31111 times.
5257759 for(int32_t j=0; j<168; j++)
3750 {
3751
3/4
✓ Branch 0 taken 2613324 times.
✓ Branch 1 taken 2613324 times.
✓ Branch 2 taken 2613324 times.
✗ Branch 3 not taken.
5226648 if(j&1 && interpol)
3752 {
3753 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3754 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3755 }
3756 else
3757 {
3758 5226648 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3759 }
3760
3761
1/2
✓ Branch 0 taken 5226648 times.
✗ Branch 1 not taken.
5226648 if(ofs)
3762 {
3763
2/2
✓ Branch 0 taken 1338021888 times.
✓ Branch 1 taken 5226648 times.
1343248536 for(int32_t k=0; k<256; k++)
3764 {
3765 1338021888 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3766 1338021888 }
3767 5226648 }
3768 5226648 }
3769 31111 }
3770
3771 4848 void draw_fuzzy(int32_t fuzz)
3772 // draws from right half of scrollbuf to framebuf
3773 {
3774 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3775 byte *start, *si, *di;
3776
3777
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4848 times.
4848 if(fuzz<1)
3778 fuzz = 1;
3779
3780 4848 xstep = 128%fuzz;
3781
3782
2/2
✓ Branch 0 taken 1010 times.
✓ Branch 1 taken 3838 times.
4848 if(xstep > 0)
3783 3838 xstep = fuzz-xstep;
3784
3785 4848 ystep = 112%fuzz;
3786
3787
2/2
✓ Branch 0 taken 1414 times.
✓ Branch 1 taken 3434 times.
4848 if(ystep > 0)
3788 3434 ystep = fuzz-ystep;
3789
3790 4848 firsty = 1;
3791
3792
2/2
✓ Branch 0 taken 4848 times.
✓ Branch 1 taken 174932 times.
179780 for(y=0; y<224;)
3793 {
3794 174932 start = &(scrollbuf->line[y][256]);
3795
3796
4/4
✓ Branch 0 taken 172508 times.
✓ Branch 1 taken 1088376 times.
✓ Branch 2 taken 1085952 times.
✓ Branch 3 taken 174932 times.
1260884 for(dy=0; dy<ystep && dy+y<224; dy++)
3797 {
3798 1085952 si = start;
3799 1085952 di = &(framebuf->line[y+dy][0]);
3800 1085952 i = xstep;
3801 1085952 firstx = 1;
3802
3803
2/2
✓ Branch 0 taken 278003712 times.
✓ Branch 1 taken 1085952 times.
279089664 for(dx=0; dx<256; dx++)
3804 {
3805 278003712 *(di++) = *si;
3806
3807
2/2
✓ Branch 0 taken 234248896 times.
✓ Branch 1 taken 43754816 times.
278003712 if(++i >= fuzz)
3808 {
3809
2/2
✓ Branch 0 taken 42668864 times.
✓ Branch 1 taken 1085952 times.
43754816 if(!firstx)
3810 42668864 si += fuzz;
3811 else
3812 {
3813 1085952 si += fuzz-xstep;
3814 1085952 firstx = 0;
3815 }
3816
3817 43754816 i = 0;
3818 43754816 }
3819 278003712 }
3820 1085952 }
3821
3822
2/2
✓ Branch 0 taken 170084 times.
✓ Branch 1 taken 4848 times.
174932 if(!firsty)
3823 170084 y += fuzz;
3824 else
3825 {
3826 4848 y += ystep;
3827 4848 ystep = fuzz;
3828 4848 firsty = 0;
3829 }
3830 }
3831 4848 }
3832
3833 9287337 void updatescr(bool allowwavy)
3834 {
3835
4/6
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 9287220 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 117 times.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
9287337 static BITMAP *wavybuf = create_bitmap_ex(8,256,224);
3836
4/6
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 9287220 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 117 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 117 times.
9287337 static BITMAP *panorama = create_bitmap_ex(8,256,224);
3837
3838
2/2
✓ Branch 0 taken 9260572 times.
✓ Branch 1 taken 26765 times.
9287337 if(toogam)
3839 {
3840 26765 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3841 26765 }
3842
3843
1/2
✓ Branch 0 taken 9287337 times.
✗ Branch 1 not taken.
9287337 if(Showpal)
3844 dump_pal(framebuf);
3845
3846
2/2
✓ Branch 0 taken 8986105 times.
✓ Branch 1 taken 301232 times.
9287337 if(!Playing)
3847 301232 black_opening_count=0;
3848
3849
2/2
✓ Branch 0 taken 9213945 times.
✓ Branch 1 taken 73392 times.
9287337 if(black_opening_count<0) //shape is opening up
3850 {
3851 73392 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3852
3853
2/4
✓ Branch 0 taken 73392 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73392 times.
73392 if(Advance||(!Paused))
3854 {
3855 73392 ++black_opening_count;
3856 73392 }
3857 73392 }
3858
2/2
✓ Branch 0 taken 9187809 times.
✓ Branch 1 taken 26136 times.
9213945 else if(black_opening_count>0) //shape is closing
3859 {
3860 26136 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3861
3862
2/4
✓ Branch 0 taken 26136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26136 times.
26136 if(Advance||(!Paused))
3863 {
3864 26136 --black_opening_count;
3865 26136 }
3866 26136 }
3867
3868
3/4
✓ Branch 0 taken 9189317 times.
✓ Branch 1 taken 98020 times.
✓ Branch 2 taken 9189317 times.
✗ Branch 3 not taken.
9287337 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3869 {
3870 black_opening_shape = bosCIRCLE;
3871 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3872 refreshTints();
3873 refreshpal=true;
3874 }
3875
3876
2/2
✓ Branch 0 taken 9033135 times.
✓ Branch 1 taken 254202 times.
9287337 if(refreshpal)
3877 {
3878 254202 refreshpal=false;
3879 254202 RAMpal[253] = _RGB(0,0,0);
3880 254202 RAMpal[254] = _RGB(63,63,63);
3881 254202 hw_palette = &RAMpal;
3882 254202 update_hw_pal = true;
3883
3884 254202 create_rgb_table(&rgb_table, RAMpal, NULL);
3885 254202 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
3886 254202 memcpy(&trans_table2, &trans_table, sizeof(COLOR_MAP));
3887
3888
2/2
✓ Branch 0 taken 65075712 times.
✓ Branch 1 taken 254202 times.
65329914 for(int32_t q=0; q<PAL_SIZE; q++)
3889 {
3890 65075712 trans_table2.data[0][q] = q;
3891 65075712 trans_table2.data[q][q] = q;
3892 65075712 }
3893 254202 }
3894
3895 9287337 bool clearwavy = (wavy <= 0);
3896
3897
2/2
✓ Branch 0 taken 7655 times.
✓ Branch 1 taken 9279682 times.
9287337 if(wavy <= 0)
3898 {
3899 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3900 9279682 wavy = (DMaps[currdmap].flags&dmfWAVY ? 4 : 0);
3901 9279682 }
3902
3903 9287337 blit(framebuf, wavybuf, 0, 0, 0, 0, 256, 224);
3904
3905
6/6
✓ Branch 0 taken 31361 times.
✓ Branch 1 taken 9255976 times.
✓ Branch 2 taken 31239 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31111 times.
9287337 if(wavy && Playing && allowwavy)
3906 {
3907 31111 draw_wavy(framebuf, wavybuf, wavy,false);
3908 31111 }
3909
3910
2/2
✓ Branch 0 taken 9279682 times.
✓ Branch 1 taken 7655 times.
9287337 if(clearwavy)
3911 9279682 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3912
2/4
✓ Branch 0 taken 7655 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7655 times.
7655 else if(Playing && !Paused)
3913 7655 wavy--; // Wavy was set by a script. Decrement it.
3914
3915
5/6
✓ Branch 0 taken 8986105 times.
✓ Branch 1 taken 301232 times.
✓ Branch 2 taken 259574 times.
✓ Branch 3 taken 8726531 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 259574 times.
9287337 if(Playing && msgpos && !screenscrolling)
3916 {
3917
1/2
✓ Branch 0 taken 259574 times.
✗ Branch 1 not taken.
259574 if(!(msg_bg_display_buf->clip))
3918 259574 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,168);
3919
1/2
✓ Branch 0 taken 259574 times.
✗ Branch 1 not taken.
259574 if(!(msg_portrait_display_buf->clip))
3920 259574 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,168);
3921
1/2
✓ Branch 0 taken 259574 times.
✗ Branch 1 not taken.
259574 if(!(msg_txt_display_buf->clip))
3922 259574 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,168);
3923 259574 }
3924
3925 /*
3926 if(!(msg_txt_display_buf->clip) && Playing && msgpos && !screenscrolling)
3927 {
3928 BITMAP* subBmp = 0;
3929 masked_blit(msg_txt_display_buf,subBmp,0,0,0,playing_field_offset,256,168);
3930 // masked_blit(msg_txt_display_buf,subBmp,0,playing_field_offset,256,168);
3931 draw_trans_sprite(framebuf, subBmp, 0, playing_field_offset);
3932 destroy_bitmap(subBmp);
3933 //void draw_sprite_ex(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t mode, int32_t flip);
3934 // masked_blit(msg_txt_display_buf,framebuf,0,0,0,playing_field_offset,256,168);
3935 //void masked_blit(BITMAP *source, BITMAP *dest, int32_t source_x, int32_t source_y, int32_t dest_x, int32_t dest_y, int32_t width, int32_t height);
3936 }
3937 */
3938
3939
2/2
✓ Branch 0 taken 9246280 times.
✓ Branch 1 taken 41057 times.
9287337 bool nosubscr = (tmpscr->flags3&fNOSUBSCR && !(tmpscr->flags3&fNOSUBSCROFFSET));
3940
3941
2/2
✓ Branch 0 taken 9250905 times.
✓ Branch 1 taken 36432 times.
9287337 if(nosubscr)
3942 {
3943 36432 rectfill(panorama,0,0,255,passive_subscreen_height/2,0);
3944 36432 rectfill(panorama,0,168+passive_subscreen_height/2,255,168+passive_subscreen_height-1,0);
3945 36432 blit(wavybuf,panorama,0,playing_field_offset,0,passive_subscreen_height/2,256,224-passive_subscreen_height);
3946 36432 }
3947
3948 //TODO: Optimize blit 'overcalls' -Gleeok
3949
2/2
✓ Branch 0 taken 36432 times.
✓ Branch 1 taken 9250905 times.
9287337 BITMAP *source = nosubscr ? panorama : wavybuf;
3950 9287337 blit(source,framebuf,0,0,0,0,256,224);
3951
3952 9287337 update_hw_screen();
3953 9287337 }
3954
3955 //----------------------------------------------------------------
3956
3957 static PALETTE syspal;
3958 int32_t onGUISnapshot()
3959 {
3960 char buf[200];
3961 int32_t num=0;
3962 do
3963 {
3964 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3965 }
3966 while(num<99999 && exists(buf));
3967
3968 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3969 InfoDialog("Error", "Failed to save snapshot").show();
3970
3971 return D_O_K;
3972 }
3973
3974 int32_t onNonGUISnapshot()
3975 {
3976 PALETTE temppal;
3977 get_palette(temppal);
3978 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3979
3980 char buf[200];
3981 int32_t num=0;
3982
3983 do
3984 {
3985 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3986 }
3987 while(num<99999 && exists(buf));
3988
3989 if (tmpscr->flags3&fNOSUBSCR && !(key[KEY_ALT]))
3990 {
3991 BITMAP *b = create_bitmap_ex(8,256,168);
3992 clear_to_color(b,0);
3993 blit(framebuf,b,0,passive_subscreen_height/2,0,0,256,168);
3994 alleg4_save_bitmap(b, SnapshotScale, buf);
3995 destroy_bitmap(b);
3996 }
3997 else
3998 {
3999 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
4000 }
4001
4002 return D_O_K;
4003 }
4004
4005 int32_t onSnapshot()
4006 {
4007 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
4008 {
4009 onGUISnapshot();
4010 }
4011 else
4012 {
4013 onNonGUISnapshot();
4014 }
4015
4016 return D_O_K;
4017 }
4018
4019 int32_t onSaveMapPic()
4020 {
4021 int32_t mapres2 = 0;
4022 char buf[200];
4023 int32_t num=0;
4024 mapscr tmpscr_b[2];
4025 mapscr tmpscr_c[6];
4026 BITMAP* _screen_draw_buffer = NULL;
4027 _screen_draw_buffer = create_bitmap_ex(8,256,224);
4028 set_clip_state(_screen_draw_buffer,1);
4029
4030 for(int32_t i=0; i<6; ++i)
4031 {
4032 tmpscr_c[i] = tmpscr2[i];
4033 tmpscr2[i].zero_memory();
4034
4035 if(i>=2)
4036 {
4037 continue;
4038 }
4039
4040 tmpscr_b[i] = tmpscr[i];
4041 tmpscr[i].zero_memory();
4042 }
4043
4044 do
4045 {
4046 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
4047 }
4048 while(num<99999 && exists(buf));
4049
4050 BITMAP* mappic = NULL;
4051
4052
4053 bool done=false, redraw=true;
4054
4055 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
4056
4057 if(!mappic)
4058 {
4059 enter_sys_pal();
4060 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4061 exit_sys_pal();
4062 return D_O_K;;
4063 }
4064
4065 // draw the map
4066 set_clip_rect(_screen_draw_buffer, 0, 0, _screen_draw_buffer->w, _screen_draw_buffer->h);
4067
4068 for(int32_t y=0; y<8; y++)
4069 {
4070 for(int32_t x=0; x<16; x++)
4071 {
4072 if(!displayOnMap(x, y))
4073 {
4074 rectfill(_screen_draw_buffer, 0, 0, 255, 223, WHITE);
4075 }
4076 else
4077 {
4078 int32_t s = (y<<4) + x;
4079 loadscr2(1,s,-1);
4080
4081 for(int32_t i=0; i<6; i++)
4082 {
4083 if(tmpscr[1].layermap[i]<=0)
4084 continue;
4085
4086 tmpscr2[i]=TheMaps[(tmpscr[1].layermap[i]-1)*MAPSCRS+tmpscr[1].layerscreen[i]];
4087 }
4088
4089 if(XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
4090
4091 if(XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
4092
4093 if(lenscheck(tmpscr+1,0)) putscr(_screen_draw_buffer,256,0,tmpscr+1);
4094 do_layer(_screen_draw_buffer, 0, 1, tmpscr+1, -256, playing_field_offset, 2);
4095
4096 if(!XOR((tmpscr+1)->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_layer(_screen_draw_buffer, 0, 2, tmpscr+1, -256, playing_field_offset, 2);
4097
4098 putscrdoors(_screen_draw_buffer,256,0,tmpscr+1);
4099 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4100 {
4101 do_layer(_screen_draw_buffer, -2, 0, tmpscr+1, -256, playing_field_offset, 2);
4102 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
4103 {
4104 do_layer(_screen_draw_buffer, -2, 1, tmpscr+1, -256, playing_field_offset, 2);
4105 do_layer(_screen_draw_buffer, -2, 2, tmpscr+1, -256, playing_field_offset, 2);
4106 }
4107 }
4108 do_layer(_screen_draw_buffer, -3, 0, tmpscr+1, -256, playing_field_offset, 2); // Freeform combos!
4109
4110 if(!XOR((tmpscr+1)->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_layer(_screen_draw_buffer, 0, 3, tmpscr+1, -256, playing_field_offset, 2);
4111
4112 do_layer(_screen_draw_buffer, 0, 4, tmpscr+1, -256, playing_field_offset, 2);
4113 do_layer(_screen_draw_buffer, -1, 0, tmpscr+1, -256, playing_field_offset, 2);
4114 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
4115 {
4116 do_layer(_screen_draw_buffer, -1, 1, tmpscr+1, -256, playing_field_offset, 2);
4117 do_layer(_screen_draw_buffer, -1, 2, tmpscr+1, -256, playing_field_offset, 2);
4118 }
4119 do_layer(_screen_draw_buffer, 0, 5, tmpscr+1, -256, playing_field_offset, 2);
4120 do_layer(_screen_draw_buffer, 0, 6, tmpscr+1, -256, playing_field_offset, 2);
4121
4122 }
4123
4124 stretch_blit(_screen_draw_buffer, mappic, 256, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
4125 }
4126 }
4127
4128 for(int32_t i=0; i<6; ++i)
4129 {
4130 tmpscr2[i]=tmpscr_c[i];
4131
4132 if(i>=2)
4133 {
4134 continue;
4135 }
4136
4137 tmpscr[i]=tmpscr_b[i];
4138 }
4139
4140 save_bitmap(buf,mappic,RAMpal);
4141 destroy_bitmap(mappic);
4142 destroy_bitmap(_screen_draw_buffer);
4143 return D_O_K;
4144 }
4145
4146 14 void f_Quit(int32_t type)
4147 {
4148
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
14 if(type==qQUIT && !Playing)
4149 return;
4150
4151 14 bool from_menu = is_sys_pal;
4152
4153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(!from_menu)
4154 {
4155 14 music_pause();
4156 14 pause_all_sfx();
4157 14 sys_mouse();
4158 14 }
4159 14 enter_sys_pal();
4160 14 clear_keybuf();
4161
4162
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 if (replay_version_check(0, 10))
4163 13 replay_poll();
4164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (replay_is_replaying())
4165 14 replay_peek_quit();
4166
4167
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if (!replay_is_replaying())
4168 switch(type)
4169 {
4170 case qQUIT:
4171 onQuit();
4172 break;
4173
4174 case qRESET:
4175 onReset();
4176 break;
4177
4178 case qEXIT:
4179 onExit();
4180 break;
4181 }
4182
4183
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(Quit)
4184 {
4185 14 kill_sfx();
4186 14 music_stop();
4187 14 exit_sys_pal();
4188 14 update_hw_screen();
4189 14 }
4190 else
4191 {
4192 exit_sys_pal();
4193 if(!from_menu)
4194 {
4195 music_resume();
4196 resume_all_sfx();
4197 }
4198 }
4199
4200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(!from_menu)
4201 14 game_mouse();
4202 14 eat_buttons();
4203
4204 14 zc_readrawkey(KEY_ESC);
4205
4206 14 zc_readrawkey(KEY_ENTER);
4207 14 }
4208
4209 //----------------------------------------------------------------
4210
4211 int32_t onNoWalls()
4212 {
4213 cheats_enqueue(Cheat::Walls);
4214 return D_O_K;
4215 }
4216
4217 int32_t onIgnoreSideview()
4218 {
4219 cheats_enqueue(Cheat::IgnoreSideView);
4220 return D_O_K;
4221 }
4222
4223 9287211 int32_t input_idle(bool checkmouse)
4224 {
4225 static int32_t mx, my, mz, mb;
4226
4227
4/6
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461754 times.
✓ Branch 3 taken 6825457 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2461754 times.
11748965 if(keypressed() || zc_key_pressed() ||
4228
4/8
✓ Branch 0 taken 2461754 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461754 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2461754 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2461754 times.
✗ Branch 7 not taken.
2461754 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4229 {
4230 6825457 idle_count = 0;
4231
4232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6825457 times.
6825457 if(active_count < MAX_ACTIVE)
4233 {
4234 6825457 ++active_count;
4235 6825457 }
4236 6825457 }
4237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2461754 times.
2461754 else if(idle_count < MAX_IDLE)
4238 {
4239 2461754 ++idle_count;
4240 2461754 active_count = 0;
4241 2461754 }
4242
4243 9287211 mx = mouse_x;
4244 9287211 my = mouse_y;
4245 9287211 mz = mouse_z;
4246 9287211 mb = mouse_b;
4247
4248 9287211 return idle_count;
4249 }
4250
4251 int32_t onGoFast()
4252 {
4253 cheats_enqueue(Cheat::Fast);
4254 return D_O_K;
4255 }
4256
4257 int32_t onKillCheat()
4258 {
4259 cheats_enqueue(Cheat::Kill);
4260 return D_O_K;
4261 }
4262
4263 int32_t onSecretsCheat()
4264 {
4265 cheats_enqueue(Cheat::TrigSecrets);
4266 return D_O_K;
4267 }
4268 int32_t onSecretsCheatPerm()
4269 {
4270 cheats_enqueue(Cheat::TrigSecretsPerm);
4271 return D_O_K;
4272 }
4273
4274 int32_t onShowLayer0()
4275 {
4276 show_layer_0 = !show_layer_0;
4277 return D_O_K;
4278 }
4279 int32_t onShowLayer1()
4280 {
4281 show_layer_1 = !show_layer_1;
4282 return D_O_K;
4283 }
4284 int32_t onShowLayer2()
4285 {
4286 show_layer_2 = !show_layer_2;
4287 return D_O_K;
4288 }
4289 int32_t onShowLayer3()
4290 {
4291 show_layer_3 = !show_layer_3;
4292 return D_O_K;
4293 }
4294 int32_t onShowLayer4()
4295 {
4296 show_layer_4 = !show_layer_4;
4297 return D_O_K;
4298 }
4299 int32_t onShowLayer5()
4300 {
4301 show_layer_5 = !show_layer_5;
4302 return D_O_K;
4303 }
4304 int32_t onShowLayer6()
4305 {
4306 show_layer_6 = !show_layer_6;
4307 return D_O_K;
4308 }
4309 int32_t onShowLayerO()
4310 {
4311 show_layer_over=!show_layer_over;
4312 return D_O_K;
4313 }
4314 int32_t onShowLayerP()
4315 {
4316 show_layer_push=!show_layer_push;
4317 return D_O_K;
4318 }
4319 int32_t onShowLayerS()
4320 {
4321 show_sprites=!show_sprites;
4322 return D_O_K;
4323 }
4324 int32_t onShowLayerF()
4325 {
4326 show_ffcs=!show_ffcs;
4327 return D_O_K;
4328 }
4329 int32_t onShowLayerW()
4330 {
4331 show_walkflags=!show_walkflags;
4332 if(show_walkflags)
4333 show_effectflags = false;
4334 return D_O_K;
4335 }
4336 int32_t onShowLayerE()
4337 {
4338 show_effectflags=!show_effectflags;
4339 if(show_effectflags)
4340 show_walkflags = false;
4341 return D_O_K;
4342 }
4343 int32_t onShowFFScripts()
4344 {
4345 show_ff_scripts=!show_ff_scripts;
4346 return D_O_K;
4347 }
4348 int32_t onShowHitboxes()
4349 {
4350 show_hitboxes=!show_hitboxes;
4351 return D_O_K;
4352 }
4353 int32_t onShowInfoOpacity()
4354 {
4355 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4356 zc_set_config("zc","debug_info_opacity",info_opacity);
4357 return D_O_K;
4358 }
4359
4360 int32_t onLightSwitch()
4361 {
4362 cheats_enqueue(Cheat::Light);
4363 return D_O_K;
4364 }
4365
4366 int32_t onGoTo();
4367 int32_t onGoToComplete();
4368
4369 9287211 bool handle_close_btn_quit()
4370 {
4371
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(close_button_quit)
4372 {
4373 close_button_quit=false;
4374 f_Quit(qEXIT);
4375 }
4376 9287211 return (exiting_program = Quit==qEXIT);
4377 }
4378
4379 9287211 void syskeys()
4380 {
4381 9287211 update_system_keys();
4382
4383 int32_t oldtitle_version;
4384
4385 9287211 poll_joystick();
4386
4387 9287211 handle_close_btn_quit();
4388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
9287211 if(Quit == qEXIT) return;
4389
4390
2/10
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9287211 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
9287211 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4391 {
4392 System();
4393 }
4394
4395 9287211 mouse_down=gui_mouse_b();
4396
4397
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F1))
4398 {
4399 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4400 {
4401 halt=!halt;
4402 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4403 }
4404 else
4405 {
4406 Throttlefps=!Throttlefps;
4407 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4408 }
4409 }
4410
4411 // if(zc_readkey(KEY_F1)) Vsync=!Vsync;
4412 /*
4413 if(zc_readkey(KEY_F1)) set_bit(QHeader.rules4,qr4_NEWENEMYTILES,
4414 1-((get_bit(QHeader.rules4,qr4_NEWENEMYTILES))));
4415 */
4416
4417
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F2))
4418 {
4419 ShowFPS=!ShowFPS;
4420 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4421 }
4422
4423
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9287211 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4424
4425
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9287211 if(zc_read_system_key(KEY_F4) && Playing)
4426 {
4427 Paused=true;
4428 Advance=true;
4429 }
4430
4431
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F6)) onTryQuit();
4432
4433 #ifndef ALLEGRO_MACOSX
4434
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4435
4436
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4437 #else
4438 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4439
4440 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4441 #endif
4442
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
9287211 if(zc_read_system_key(KEY_F5)&&(Playing && currscr<128 && DMaps[currdmap].flags&dmfVIEWMAP)) onSaveMapPic();
4443
4444
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if (zc_read_system_key(KEY_F12))
4445 {
4446 onSnapshot();
4447 }
4448
4449
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9287211 if(debug_enabled && zc_read_system_key(KEY_TAB))
4450 set_debug(!get_debug());
4451
4452
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(CheatModifierKeys())
4453 {
4454 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4455 {
4456 if(!bindable_cheat(c))
4457 continue;
4458 if(get_debug() || cheat >= cheat_lvl(c))
4459 {
4460 if(checkcheat(c))
4461 cheats_hit_bind(c);
4462 }
4463 }
4464 }
4465
4466
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(volkeys)
4467 {
4468 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4469
4470 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4471
4472 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4473
4474 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4475 }
4476
4477
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
9287211 if(!get_debug() || !SystemKeys || replay_is_replaying())
4478 9287211 goto bottom;
4479
4480 if(zc_readkey(KEY_D))
4481 {
4482 details = !details;
4483 rectfill(screen,0,0,319,7,BLACK);
4484 rectfill(screen,0,8,31,239,BLACK);
4485 rectfill(screen,288,8,319,239,BLACK);
4486 rectfill(screen,32,232,287,239,BLACK);
4487 }
4488
4489 if(zc_readkey(KEY_P)) Paused=!Paused;
4490
4491 //if(zc_readkey(KEY_P)) centerHero();
4492 if(zc_readkey(KEY_A))
4493 {
4494 Paused=true;
4495 Advance=true;
4496 }
4497
4498 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4499 #ifndef ALLEGRO_MACOSX
4500 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4501
4502 if(zc_readkey(KEY_F7))
4503 {
4504 Matrix(ss_speed, ss_density, 0);
4505 game_pal();
4506 }
4507 #else
4508 // The reason these are different on Mac in the first place is that
4509 // the OS doesn't let us use F9 and F10...
4510 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4511
4512 if(zc_readkey(KEY_F9))
4513 {
4514 Matrix(ss_speed, ss_density, 0);
4515 game_pal();
4516 }
4517 #endif
4518 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4519 {
4520 //change containers
4521 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4522 {
4523 //magic containers
4524 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4525 {
4526 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4527 }
4528 else
4529 {
4530 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4531 }
4532 }
4533 else
4534 {
4535 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4536 {
4537 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4538 }
4539 else
4540 {
4541 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4542 }
4543 }
4544 }
4545
4546 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4547 {
4548 //change containers
4549 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4550 {
4551 //magic containers
4552 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4553 {
4554 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4555 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4556 //heart containers
4557 }
4558 else
4559 {
4560 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4561 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4562 }
4563 }
4564 else
4565 {
4566 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4567 {
4568 game->set_magic(zc_max(game->get_magic()-1,0));
4569 }
4570 else
4571 {
4572 game->set_life(zc_max(game->get_life()-1,0));
4573 }
4574 }
4575 }
4576
4577 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4578
4579 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4580
4581 verifyBothWeapons();
4582
4583 bottom:
4584
4585
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(input_idle(true) > after_time())
4586 {
4587 Matrix(ss_speed, ss_density, 0);
4588 game_pal();
4589 }
4590 9287211 }
4591
4592 708292 void checkQuitKeys()
4593 {
4594 #ifndef ALLEGRO_MACOSX
4595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 708292 times.
708292 if(key[KEY_F9]) f_Quit(qRESET);
4596
4597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 708292 times.
708292 if(key[KEY_F10]) f_Quit(qEXIT);
4598 #else
4599 if(key[KEY_F7]) f_Quit(qRESET);
4600
4601 if(key[KEY_F8]) f_Quit(qEXIT);
4602 #endif
4603 708292 }
4604
4605 9287211 bool CheatModifierKeys()
4606 {
4607 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4608 // to trigger cheats.
4609
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if (replay_is_replaying())
4610 9287211 return false;
4611
4612 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4613 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4614 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4615 {
4616 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4617 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4618 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4619 {
4620 return true;
4621 }
4622 }
4623 return false;
4624 9287211 }
4625
4626 //99:05:54, for some reason?
4627 #define OLDMAXTIME 21405240
4628 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4629 #define MAXTIME 1944000000
4630
4631 9287337 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4632 {
4633
1/2
✓ Branch 0 taken 9287337 times.
✗ Branch 1 not taken.
9287337 if(zcmusic!=NULL)
4634 {
4635 zcmusic_poll();
4636 }
4637 9287337 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4638
4639 9287337 updatescr(allowwavy);
4640
4641 9287337 Advance=false;
4642
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9287337 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9287337 times.
9287337 while(Paused && !Advance && !Quit)
4643 {
4644 // have to call this, otherwise we'll get an infinite loop
4645 syskeys();
4646 if(allowF6Script)
4647 {
4648 FFCore.runF6Engine();
4649 }
4650 zc_throttle_fps();
4651
4652 #ifdef _WIN32
4653
4654 if(use_dwm_flush)
4655 {
4656 do_DwmFlush();
4657 }
4658
4659 #endif
4660
4661 // to keep music playing
4662 if(zcmusic!=NULL)
4663 {
4664 zcmusic_poll();
4665 }
4666
4667 update_hw_screen();
4668 }
4669
4670
2/2
✓ Branch 0 taken 9287225 times.
✓ Branch 1 taken 112 times.
9287337 if(Quit)
4671 112 return;
4672
4673
3/4
✓ Branch 0 taken 8986096 times.
✓ Branch 1 taken 301129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8986096 times.
9287225 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4674 8986096 game->change_time(1);
4675
4676 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4677
4678 9287225 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4679
2/2
✓ Branch 0 taken 20428 times.
✓ Branch 1 taken 9266797 times.
9287225 if (replay_version_check(0, 16))
4680 9266797 should_reset_down_state = replay_version_check(11, 16);
4681
2/2
✓ Branch 0 taken 6949680 times.
✓ Branch 1 taken 2337545 times.
9287225 if (should_reset_down_state)
4682 {
4683
2/2
✓ Branch 0 taken 42075810 times.
✓ Branch 1 taken 2337545 times.
44413355 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4684 42075810 down_control_states[i] = raw_control_state[i];
4685 2337545 }
4686
4687
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9287211 times.
9287225 if (replay_is_active())
4688 {
4689
2/2
✓ Branch 0 taken 1270449 times.
✓ Branch 1 taken 8016762 times.
9287211 if (replay_version_check(3))
4690 8016762 replay_poll();
4691
4692
4/4
✓ Branch 0 taken 6946098 times.
✓ Branch 1 taken 2341113 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 6845563 times.
9287211 if (replay_version_check(11) || replay_version_check(6, 8))
4693 2441648 replay_peek_input();
4694 9287211 }
4695
4696 9287225 load_control_called_this_frame = false;
4697
4698 9287225 poll_keyboard();
4699 9287225 update_keys();
4700
4701 9287225 ++frame;
4702
4703
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9287211 times.
9287225 if (replay_is_replaying())
4704 9287211 replay_do_cheats();
4705 9287225 syskeys();
4706
4707 // The mouse variables can change from the mouse thread at anytime during a frame,
4708 // so save the result at the start so that replaying is consistent.
4709 9287225 script_mouse_x = gui_mouse_x();
4710 9287225 script_mouse_y = gui_mouse_y();
4711 9287225 script_mouse_z = mouse_z;
4712 9287225 script_mouse_b = mouse_b;
4713
4714 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4715 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4716 // approach here means it doesn't matter which call adds the cheat.
4717 9287225 cheats_execute_queued();
4718
4719
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 9287211 times.
9287225 if (replay_is_replaying())
4720 9287211 replay_peek_quit();
4721
2/2
✓ Branch 0 taken 9287211 times.
✓ Branch 1 taken 14 times.
9287225 if (GameFlags & GAMEFLAG_TRYQUIT)
4722 14 replay_step_quit(0);
4723
2/2
✓ Branch 0 taken 2934 times.
✓ Branch 1 taken 9284291 times.
9287225 if(allowF6Script)
4724 9284291 FFCore.runF6Engine();
4725
2/2
✓ Branch 0 taken 301 times.
✓ Branch 1 taken 9286924 times.
9287225 if (Quit)
4726 301 replay_step_quit(Quit);
4727 // Someday... maybe install a Turbo button here?
4728 9287225 zc_throttle_fps();
4729
4730 #ifdef _WIN32
4731
4732 if(use_dwm_flush)
4733 {
4734 do_DwmFlush();
4735 }
4736
4737 #endif
4738
4739 //textprintf_ex(screen,font,0,72,254,BLACK,"%d %d", lastentrance, lastentrance_dmap);
4740
2/2
✓ Branch 0 taken 68758 times.
✓ Branch 1 taken 9218467 times.
9287225 if(sfxcleanup)
4741 9218467 sfx_cleanup();
4742
4743 9287225 jit_poll();
4744
4745 #ifdef __EMSCRIPTEN__
4746 // Yield the main thread back to the browser occasionally.
4747 if (is_headless())
4748 {
4749 static int rate = 10000;
4750 static int force_yield = rate;
4751 if (force_yield++ >= rate)
4752 {
4753 force_yield = 0;
4754 emscripten_sleep(0);
4755 }
4756 }
4757 #endif
4758
4759
4/6
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 9287108 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 117 times.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
9287225 static bool test_mode_auto_restart = zc_get_config("zeldadx", "test_mode_auto_restart", false);
4760
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9287225 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9287225 if (zqtesting_mode && test_mode_auto_restart)
4761 {
4762 static auto last_write_time = fs::last_write_time(qstpath);
4763 static auto last_check = std::chrono::system_clock::now();
4764
4765 if (std::chrono::system_clock::now() - last_check > 200ms)
4766 {
4767 last_check = std::chrono::system_clock::now();
4768 auto write_time = fs::last_write_time(qstpath);
4769 if (last_write_time != write_time)
4770 {
4771 last_write_time = write_time;
4772 disableClickToFreeze = false;
4773 Quit = qRESET;
4774 replay_quit();
4775 }
4776 }
4777 }
4778 9287337 }
4779
4780 101 void zapout()
4781 {
4782 101 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4783 101 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4784
4785 101 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4786 101 script_drawing_commands.Clear();
4787
4788 // zap out
4789
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 2424 times.
2525 for(int32_t i=1; i<=24; i++)
4790 {
4791 2424 draw_fuzzy(i);
4792 2424 advanceframe(true);
4793
4794
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
2424 if(Quit)
4795 {
4796 break;
4797 }
4798 2424 }
4799 101 }
4800
4801 101 void zapin()
4802 {
4803 101 FFCore.warpScriptCheck();
4804 101 draw_screen(tmpscr);
4805 101 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
4806 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4807 101 blit(framebuf,scrollbuf,0,0,256,0,256,224);
4808
4809 // zap out
4810 101 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4811
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 2424 times.
2525 for(int32_t i=24; i>=1; i--)
4812 {
4813 2424 draw_fuzzy(i);
4814 2424 advanceframe(true);
4815
4816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2424 times.
2424 if(Quit)
4817 {
4818 break;
4819 }
4820 2424 }
4821 101 }
4822
4823
4824 65 void wavyout(bool showhero)
4825 {
4826 65 draw_screen(tmpscr, showhero);
4827 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4828
4829 65 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4830 65 clear_to_color(wavebuf,0);
4831 65 blit(framebuf,wavebuf,0,0,16,0,256,224);
4832
4833 static PALETTE wavepal;
4834
4835 int32_t ofs;
4836 65 int32_t amplitude=8;
4837
4838 65 int32_t wavelength=4;
4839 65 double palpos=0, palstep=4, palstop=126;
4840
4841 65 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4842
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 2730 times.
2795 for(int32_t i=0; i<168; i+=wavelength)
4843 {
4844
2/2
✓ Branch 0 taken 698880 times.
✓ Branch 1 taken 2730 times.
701610 for(int32_t l=0; l<256; l++)
4845 {
4846 698880 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(63-RAMpal[l].r))),0,63);
4847 698880 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(63-RAMpal[l].g))),0,63);
4848 698880 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(63-RAMpal[l].b))),0,63);
4849 698880 }
4850
4851 2730 palpos+=palstep;
4852
4853
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
2730 if(palpos>=0)
4854 {
4855 2730 hw_palette = &wavepal;
4856 2730 update_hw_pal = true;
4857 2730 }
4858 else
4859 {
4860 hw_palette = &RAMpal;
4861 update_hw_pal = true;
4862 }
4863
4864
2/2
✓ Branch 0 taken 458640 times.
✓ Branch 1 taken 2730 times.
461370 for(int32_t j=0; j+playing_field_offset<224; j++)
4865 {
4866
2/2
✓ Branch 0 taken 117411840 times.
✓ Branch 1 taken 458640 times.
117870480 for(int32_t k=0; k<256; k++)
4867 {
4868 117411840 ofs=0;
4869
4870
4/4
✓ Branch 0 taken 57308160 times.
✓ Branch 1 taken 60103680 times.
✓ Branch 2 taken 28654080 times.
✓ Branch 3 taken 28654080 times.
117411840 if((j<i)&&(j&1))
4871 {
4872 28654080 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4873 28654080 }
4874
4875 117411840 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4876 117411840 }
4877 458640 }
4878
4879 2730 advanceframe(true);
4880
4881 // animate_combos();
4882
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2730 times.
2730 if(Quit)
4883 break;
4884 2730 }
4885
4886 65 destroy_bitmap(wavebuf);
4887 65 }
4888
4889 65 void wavyin()
4890 {
4891 65 draw_screen(tmpscr);
4892 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
4893
4894 65 BITMAP *wavebuf = create_bitmap_ex(8,288,224);
4895 65 clear_to_color(wavebuf,0);
4896 65 blit(framebuf,wavebuf,0,0,16,0,256,224);
4897
4898 static PALETTE wavepal;
4899
4900 //Breaks dark rooms.
4901 //In any case I don't think we need this, since palette is already loaded in doWarp() (famous last words...) -DD
4902 /*
4903 loadfullpal();
4904 loadlvlpal(DMaps[currdmap].color);
4905 ringcolor(false);
4906 */
4907 65 refreshpal=false;
4908 int32_t ofs;
4909 65 int32_t amplitude=8;
4910 65 int32_t wavelength=4;
4911 65 double palpos=168, palstep=4, palstop=126;
4912
4913 65 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4914
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 2730 times.
2795 for(int32_t i=0; i<168; i+=wavelength)
4915 {
4916
2/2
✓ Branch 0 taken 698880 times.
✓ Branch 1 taken 2730 times.
701610 for(int32_t l=0; l<256; l++)
4917 {
4918 698880 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(63-RAMpal[l].r))),0,63);
4919 698880 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(63-RAMpal[l].g))),0,63);
4920 698880 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(63-RAMpal[l].b))),0,63);
4921 698880 }
4922
4923 2730 palpos-=palstep;
4924
4925
1/2
✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
2730 if(palpos>=0)
4926 {
4927 2730 hw_palette = &wavepal;
4928 2730 update_hw_pal = true;
4929 2730 }
4930 else
4931 {
4932 hw_palette = &RAMpal;
4933 update_hw_pal = true;
4934 }
4935
4936
2/2
✓ Branch 0 taken 458640 times.
✓ Branch 1 taken 2730 times.
461370 for(int32_t j=0; j+playing_field_offset<224; j++)
4937 {
4938
2/2
✓ Branch 0 taken 117411840 times.
✓ Branch 1 taken 458640 times.
117870480 for(int32_t k=0; k<256; k++)
4939 {
4940 117411840 ofs=0;
4941
4942
4/4
✓ Branch 0 taken 59404800 times.
✓ Branch 1 taken 58007040 times.
✓ Branch 2 taken 30051840 times.
✓ Branch 3 taken 29352960 times.
117411840 if((j<(167-i))&&(j&1))
4943 {
4944 29352960 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/168.0))*amplitude);
4945 29352960 }
4946
4947 117411840 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4948 117411840 }
4949 458640 }
4950
4951 2730 advanceframe(true);
4952 // animate_combos();
4953
4954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2730 times.
2730 if(Quit)
4955 break;
4956 2730 }
4957
4958 65 destroy_bitmap(wavebuf);
4959 65 }
4960
4961 2168 void blackscr(int32_t fcnt,bool showsubscr)
4962 {
4963 2168 reset_pal_cycling();
4964 2168 script_drawing_commands.Clear();
4965
4966 2168 FFCore.warpScriptCheck();
4967 2168 bool showtime = game->should_show_time();
4968
2/2
✓ Branch 0 taken 2168 times.
✓ Branch 1 taken 64970 times.
67138 while(fcnt>0)
4969 {
4970 64970 clear_bitmap(framebuf);
4971
4972
2/2
✓ Branch 0 taken 25080 times.
✓ Branch 1 taken 39890 times.
64970 if(showsubscr)
4973 {
4974 39890 put_passive_subscr(framebuf,0,passive_subscreen_offset,showtime,sspUP);
4975
3/4
✓ Branch 0 taken 39890 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 750 times.
✓ Branch 3 taken 39140 times.
39890 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4976 {
4977 750 do_script_draws(framebuf, tmpscr, 0, playing_field_offset);
4978 750 }
4979 39890 }
4980
4981 64970 advanceframe(true);
4982
4983
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64970 times.
64970 if(Quit)
4984 break;
4985
4986 64970 --fcnt;
4987 }
4988 2168 }
4989
4990 1013 void openscreen(int32_t shape)
4991 {
4992 1013 reset_pal_cycling();
4993 1013 black_opening_count=0;
4994
4995
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 913 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100 times.
1013 if(COOLSCROLL || shape>-1)
4996 {
4997 913 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4998 913 return;
4999 }
5000 else
5001 {
5002 100 Hero.setDontDraw(true);
5003 100 show_subscreen_dmap_dots=false;
5004 100 show_subscreen_numbers=false;
5005 // show_subscreen_items=false;
5006 100 show_subscreen_life=false;
5007 }
5008
5009 100 int32_t x=128;
5010
5011 100 FFCore.warpScriptCheck();
5012
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 8000 times.
8100 for(int32_t i=0; i<80; i++)
5013 {
5014 8000 draw_screen(tmpscr);
5015 //? draw_screen already draws the subscreen -DD
5016 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
5017 8000 x=128-(((i*128/80)/8)*8);
5018
5019
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8000 times.
8000 if(x>0)
5020 {
5021 8000 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
5022 8000 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
5023 8000 }
5024
5025 8000 advanceframe(true);
5026
5027
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8000 times.
8000 if(Quit)
5028 {
5029 break;
5030 }
5031 8000 }
5032
5033 100 Hero.setDontDraw(false);
5034 100 show_subscreen_items=true;
5035 100 show_subscreen_dmap_dots=true;
5036 1013 }
5037
5038 void closescreen(int32_t shape)
5039 {
5040 reset_pal_cycling();
5041 black_opening_count=0;
5042
5043 if(COOLSCROLL || shape>-1)
5044 {
5045 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
5046 return;
5047 }
5048 else
5049 {
5050 Hero.setDontDraw(true);
5051 show_subscreen_dmap_dots=false;
5052 show_subscreen_numbers=false;
5053 // show_subscreen_items=false;
5054 show_subscreen_life=false;
5055 }
5056
5057 int32_t x=128;
5058
5059 FFCore.warpScriptCheck();
5060 for(int32_t i=79; i>=0; --i)
5061 {
5062 draw_screen(tmpscr);
5063 //? draw_screen already draws the subscreen -DD
5064 //put_passive_subscr(framebuf,0,passive_subscreen_offset,false,sspUP);
5065 x=128-(((i*128/80)/8)*8);
5066
5067 if(x>0)
5068 {
5069 rectfill(framebuf,0,playing_field_offset,x,167+playing_field_offset,0);
5070 rectfill(framebuf,256-x,playing_field_offset,255,167+playing_field_offset,0);
5071 }
5072
5073 advanceframe(true);
5074
5075 if(Quit)
5076 {
5077 break;
5078 }
5079 }
5080
5081 Hero.setDontDraw(false);
5082 show_subscreen_items=true;
5083 show_subscreen_dmap_dots=true;
5084 }
5085
5086 179 int32_t TriforceCount()
5087 {
5088 179 int32_t c=0;
5089
5090
2/2
✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 179 times.
1611 for(int32_t i=1; i<=8; i++)
5091
2/2
✓ Branch 0 taken 388 times.
✓ Branch 1 taken 1044 times.
2476 if(game->lvlitems[i]&liTRIFORCE)
5092 1044 ++c;
5093
5094 179 return c;
5095 }
5096
5097 int32_t onCustomGame()
5098 {
5099 int32_t file = getsaveslot();
5100
5101 if(file < 0)
5102 return D_O_K;
5103
5104 bool ret = (custom_game(file)!=0);
5105 return ret ? D_CLOSE : D_O_K;
5106 }
5107
5108 int32_t onContinue()
5109 {
5110 return D_CLOSE;
5111 }
5112
5113 int32_t onEsc() // Unused?? -L
5114 {
5115 return zc_getrawkey(KEY_ESC, true)?D_CLOSE:D_O_K;
5116 }
5117
5118 int32_t onVsync()
5119 {
5120 Throttlefps = !Throttlefps;
5121 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
5122 return D_O_K;
5123 }
5124
5125 int32_t onWinPosSave()
5126 {
5127 SaveWinPos = !SaveWinPos;
5128 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
5129 return D_O_K;
5130 }
5131 int32_t onIntegerScaling()
5132 {
5133 scaleForceInteger = !scaleForceInteger;
5134 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
5135 return D_O_K;
5136 }
5137 int32_t onStretchGame()
5138 {
5139 stretchGame = !stretchGame;
5140 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
5141 return D_O_K;
5142 }
5143
5144 int32_t onClickToFreeze()
5145 {
5146 ClickToFreeze = !ClickToFreeze;
5147 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
5148 return D_O_K;
5149 }
5150
5151 int32_t OnSaveZCConfig()
5152 {
5153 if(jwin_alert3(
5154 "Save Configuration",
5155 "Are you sure that you wish to save your present configuration settings?",
5156 "This will overwrite your prior settings!",
5157 NULL,
5158 "&Yes",
5159 "&No",
5160 NULL,
5161 'y',
5162 'n',
5163 0,
5164 get_zc_font(font_lfont)) == 1)
5165 {
5166 save_game_configs();
5167 return D_O_K;
5168 }
5169 else return D_O_K;
5170 }
5171
5172 int32_t OnnClearQuestDir()
5173 {
5174 auto current_path = fs::current_path() / "quests";
5175 if(jwin_alert3(
5176 "Clear Current Directory Cache",
5177 "Are you sure that you wish to reset where ZC Player looks for quests?",
5178 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
5179 NULL,
5180 "&Yes",
5181 "&No",
5182 NULL,
5183 'y',
5184 'n',
5185 0,
5186 get_zc_font(font_lfont)) == 1)
5187 {
5188 zc_set_config("zeldadx","quest_dir","quests");
5189 flush_config_file();
5190 strcpy(qstdir,"quests");
5191 #ifdef __EMSCRIPTEN__
5192 em_sync_fs();
5193 #endif
5194 return D_O_K;
5195 }
5196 else return D_O_K;
5197 }
5198
5199
5200 int32_t onConsoleZASM()
5201 {
5202 if ( !zasm_debugger )
5203 {
5204 AlertDialog("WARNING: ZASM Debugger",
5205 "Enabling this will open the ZASM Debugger Console"
5206 "\nThis will likely grind ZC to a halt with lag."
5207 "\nTo make any use of this, it is suggested that you read"
5208 "\nthe documentation for 'void Breakpoint(char[] string);'"
5209 " in 'ZScript_Additions.txt'"
5210 "\nThis is not recommended for normal users,"
5211 " and is only intended for ZC developers,"
5212 "\nor quest developers coding directly in ZASM"
5213 "\nAre you sure that you wish to open the ZASM Debugger?",
5214 [&](bool ret,bool)
5215 {
5216 if(ret)
5217 {
5218 FFCore.ZASMPrint(true);
5219 }
5220 }).show();
5221 return D_O_K;
5222 }
5223 else
5224 {
5225 FFCore.ZASMPrint(false);
5226 return D_O_K;
5227 }
5228 }
5229
5230
5231 int32_t onConsoleZScript()
5232 {
5233 if ( !zscript_debugger )
5234 {
5235 AlertDialog("ZScript Debugger",
5236 "Enabling this will open the ZScript Debugger Console"
5237 "\nThis will display any messages logged by scripts,"
5238 " including script errors."
5239 "\nAre you sure that you wish to open the ZScript Debugger?",
5240 [&](bool ret,bool)
5241 {
5242 if(ret)
5243 {
5244 FFCore.ZScriptConsole(true);
5245 }
5246 }).show();
5247 return D_O_K;
5248 }
5249 else
5250 {
5251 FFCore.ZScriptConsole(false);
5252 return D_O_K;
5253 }
5254 }
5255
5256 int32_t onClrConsoleOnReload()
5257 {
5258 clearConsoleOnReload = !clearConsoleOnReload;
5259 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5260 return D_O_K;
5261 }
5262 int32_t onClrConsoleOnLoad()
5263 {
5264 clearConsoleOnLoad = !clearConsoleOnLoad;
5265 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5266 return D_O_K;
5267 }
5268
5269
5270 int32_t onFrameSkip()
5271 {
5272 FrameSkip = !FrameSkip;
5273 return D_O_K;
5274 }
5275
5276 int32_t onSaveDragResize()
5277 {
5278 SaveDragResize = !SaveDragResize;
5279 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5280 return D_O_K;
5281 }
5282
5283 int32_t onDragAspect()
5284 {
5285 DragAspect = !DragAspect;
5286 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5287 return D_O_K;
5288 }
5289
5290 int32_t onTransLayers()
5291 {
5292 TransLayers = !TransLayers;
5293 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5294 return D_O_K;
5295 }
5296
5297 int32_t onNESquit()
5298 {
5299 NESquit = !NESquit;
5300 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5301 return D_O_K;
5302 }
5303
5304 int32_t onVolKeys()
5305 {
5306 volkeys = !volkeys;
5307 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5308 return D_O_K;
5309 }
5310
5311 int32_t onShowFPS()
5312 {
5313 ShowFPS = !ShowFPS;
5314 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5315 return D_O_K;
5316 }
5317
5318 1095890898 bool is_Fkey(int32_t k)
5319 {
5320
2/2
✓ Branch 0 taken 111446532 times.
✓ Branch 1 taken 984444366 times.
1095890898 switch(k)
5321 {
5322 case KEY_F1:
5323 case KEY_F2:
5324 case KEY_F3:
5325 case KEY_F4:
5326 case KEY_F5:
5327 case KEY_F6:
5328 case KEY_F7:
5329 case KEY_F8:
5330 case KEY_F9:
5331 case KEY_F10:
5332 case KEY_F11:
5333 case KEY_F12:
5334 111446532 return true;
5335 }
5336
5337 984444366 return false;
5338 1095890898 }
5339
5340 void kb_getkey(DIALOG *d);
5341
5342 //Used by all keyboard key settings dialogues.
5343 void kb_clearjoystick(DIALOG *d)
5344 {
5345 d->flags|=D_SELECTED;
5346
5347 jwin_button_proc(MSG_DRAW,d,0);
5348 jwin_draw_win(gui_bmp, (gui_bmp->w-160)/2, (gui_bmp->h-48)/2, 168, 48, FR_WIN);
5349 // text_mode(vc(11));
5350 textout_centre_ex(gui_bmp, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5351 textout_centre_ex(gui_bmp, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5352
5353 update_hw_screen(true);
5354
5355 clear_keybuf();
5356 int32_t k = next_press_key();
5357 clear_keybuf();
5358
5359 //shnarf
5360 //47=f1
5361 //59=esc
5362 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5363 // *((int32_t*)d->dp3) = k;
5364 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5365
5366
5367 d->flags&=~D_SELECTED;
5368 }
5369
5370 //Clears key to 0.
5371 //Used by all keyboard key settings dialogues.
5372 void kb_clearkey(DIALOG *d);
5373
5374 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5375 {
5376 switch(msg)
5377 {
5378 case MSG_KEY:
5379 case MSG_CLICK:
5380
5381 kb_clearjoystick(d);
5382
5383 while(gui_mouse_b())
5384 {
5385 clear_keybuf();
5386 rest(1);
5387 }
5388
5389 return D_REDRAW;
5390 }
5391
5392 return jwin_button_proc(msg,d,c);
5393 }
5394
5395 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5396 //Only used in keyboard settings dialogues to clear keys.
5397 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5398
5399 int32_t j_getbtn(DIALOG *d)
5400 {
5401 d->flags|=D_SELECTED;
5402 jwin_button_proc(MSG_DRAW,d,0);
5403 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5404 // text_mode(vc(11));
5405 int32_t y = screen->h/2 - 12;
5406 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5407 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5408 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5409
5410 update_hw_screen(true);
5411
5412 int32_t b = next_joy_input(true);
5413 if (b == -2)
5414 return D_CLOSE;
5415
5416 if(b>=0)
5417 *((int32_t*)d->dp3) = b;
5418
5419 d->flags&=~D_SELECTED;
5420
5421 if (player)
5422 player->joy_on = TRUE;
5423
5424 return D_O_K;
5425 }
5426
5427 void j_getstick(DIALOG *d)
5428 {
5429 d->flags|=D_SELECTED;
5430 jwin_button_proc(MSG_DRAW,d,0);
5431 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5432 // text_mode(vc(11));
5433 int32_t y = screen->h/2 - 12;
5434 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5435 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5436 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5437
5438 update_hw_screen(true);
5439
5440 int32_t b = next_joy_input(false);
5441
5442 if(b>=0)
5443 *((int32_t*)d->dp3) = b;
5444
5445 d->flags&=~D_SELECTED;
5446
5447 if (player)
5448 player->joy_on = TRUE;
5449 }
5450
5451 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5452 {
5453 switch(msg)
5454 {
5455 case MSG_KEY:
5456 case MSG_CLICK:
5457
5458 int ret = j_getbtn(d);
5459 if (ret != D_O_K)
5460 return ret;
5461
5462 while(gui_mouse_b()) {
5463 rest(1);
5464 clear_keybuf();
5465 }
5466
5467 return D_REDRAW;
5468 }
5469
5470 return jwin_button_proc(msg,d,c);
5471 }
5472
5473 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5474 {
5475 switch(msg)
5476 {
5477 case MSG_KEY:
5478 case MSG_CLICK:
5479
5480 j_getstick(d);
5481
5482 while(gui_mouse_b()) {
5483 rest(1);
5484 clear_keybuf();
5485 }
5486
5487 return D_REDRAW;
5488 }
5489
5490 return jwin_button_proc(msg,d,c);
5491 }
5492
5493 //shnarf
5494 extern const char *key_str[];
5495 std::string get_keystr(int key);
5496
5497 const char *pan_str[4] = { "MONO", " 1/2", " 3/4", "FULL" };
5498 //extern int32_t zcmusic_bufsz;
5499
5500 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5501 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5502 str_primary_stick[80], str_secondary_stick[80];
5503
5504 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5505 {
5506 //these are here to bypass compiler warnings about unused arguments
5507 c=c;
5508
5509 if (d->w == 1)
5510 {
5511 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5512 {
5513 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5514 return D_CLOSE;
5515 }
5516 }
5517
5518 if(msg==MSG_DRAW)
5519 {
5520 switch(d->w)
5521 {
5522 case 0:
5523 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5524 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5525 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5526 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5527 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5528 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5529 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5530 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5531 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5532 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5533 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5534 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5535 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5536 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5537 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5538 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5539 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5540 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5541 break;
5542
5543 case 1:
5544 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5545 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5546 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5547 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5548 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5549 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5550 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5551 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5552 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5553 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5554 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5555 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5556 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5557 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5558 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5559 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5560 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5561 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5562 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5563 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5564 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5565 break;
5566
5567 case 2:
5568 sprintf(str_a," %3d",midi_volume);
5569 sprintf(str_b," %3d",digi_volume);
5570 sprintf(str_l," %3d",emusic_volume);
5571 sprintf(str_m," %3dKB",zcmusic_bufsz);
5572 sprintf(str_r," %3d",sfx_volume);
5573 strcpy(str_s,pan_str[pan_style]);
5574 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5575 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5576 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5577 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5578 break;
5579 }
5580 }
5581
5582 return D_O_K;
5583 }
5584
5585 int32_t set_vol(void *dp3, int32_t d2)
5586 {
5587 switch(((int32_t*)dp3)[0])
5588 {
5589 case 0:
5590 midi_volume = zc_min(d2<<3,255);
5591 break;
5592
5593 case 1:
5594 digi_volume = zc_min(d2<<3,255);
5595 break;
5596
5597 case 2:
5598 emusic_volume = zc_min(d2<<3,255);
5599 break;
5600
5601 case 3:
5602 sfx_volume = zc_min(d2<<3,255);
5603 break;
5604 }
5605
5606 // text_mode(vc(11));
5607 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%3d",zc_min(d2<<3,255));
5608 return D_O_K;
5609 }
5610
5611 int32_t set_pan(void *dp3, int32_t d2)
5612 {
5613 pan_style = vbound(d2,0,3);
5614 // text_mode(vc(11));
5615 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5616 return D_O_K;
5617 }
5618
5619 int32_t set_buf(void *dp3, int32_t d2)
5620 {
5621 // text_mode(vc(11));
5622 zcmusic_bufsz = d2 + 1;
5623 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%3dKB",zcmusic_bufsz);
5624 return D_O_K;
5625 }
5626
5627 static int32_t gamepad_joys_list[] =
5628 {
5629 61,
5630 -1
5631 };
5632
5633 static int32_t gamepad_btn_list[] =
5634 {
5635 6,
5636 7,8,9,10,11,12,13,14,15,16,17,
5637 18,19,20,21,22,23,24,25,26,27,28,
5638 29,30,31,32,33,34,35,36,37,38,39,
5639 -1
5640 };
5641
5642 static int32_t gamepad_dirs_list[] =
5643 {
5644 40,41,42,43,
5645 44,45,46,47,
5646 48,49,50,51,
5647 52,53,54,55,
5648 56,57,58,59,
5649 60,
5650 -1
5651 };
5652
5653 static TABPANEL gamepad_tabs[] =
5654 {
5655 // (text)
5656 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5657 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5658 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5659 { NULL, 0, NULL, 0, NULL }
5660 };
5661
5662 const char *joy_list(int32_t index, int32_t *list_size)
5663 {
5664 if (index == -1)
5665 {
5666 *list_size = al_get_num_joysticks();
5667 return NULL;
5668 }
5669
5670 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5671 if (!joy)
5672 {
5673 return "?";
5674 }
5675
5676 return al_get_joystick_name(joy);
5677 }
5678
5679 117 static ListData joy__list(joy_list, &font);
5680
5681 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5682 {
5683 int32_t d2 = d->d2;
5684 int32_t ret = jwin_droplist_proc(msg,d,c);
5685
5686 if(d2!=d->d2)
5687 {
5688 joystick_index = d->d2;
5689 ret |= D_REDRAW_ALL;
5690 }
5691
5692 return ret;
5693 }
5694
5695 static DIALOG gamepad_dlg[] =
5696 {
5697 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5698 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5699 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5700 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5701 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5702 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5703 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5704 // 6
5705 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5706 // 7
5707 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5708 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5709 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5710 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5711 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5712 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5713 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5714 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5715 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5716 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5717 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5718 // 18
5719 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5720 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5721 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5722 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5723 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5724 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5725 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5726 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5727 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5728 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5729 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5730 // 29
5731 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5732 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5733 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5734 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5735 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5736 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5737 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5738 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5739 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5740 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5741 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5742 // 40
5743 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5744 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5745 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5746 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5747 // 44
5748 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5749 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5750 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5751 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5752 // 48
5753 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5754 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5755 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5756 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5757 // 52
5758 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5759 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5760 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5761 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5762 // 56
5763 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5764 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5765 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5766 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5767 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5768
5769 // 61
5770 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5771
5772 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5773 };
5774
5775 static int32_t keyboard_keys_list[] =
5776 {
5777 6,7,8,9,10,
5778 11,12,13,14,15,16,17,18,19,20,
5779 21,22,23,24,25,26,27,28,29,30,
5780 31,32,33,34,35,36,37,38,39,40,
5781 -1
5782 };
5783
5784 static int32_t keyboard_dirs_list[] =
5785 {
5786 41,42,43,44,
5787 45,46,47,48,
5788 49,50,51,52,
5789 53,54,55,56,
5790 -1
5791 };
5792
5793 static int32_t keyboard_mods_list[] =
5794 {
5795 57,58,59,60,
5796 61,62,63,64,
5797 65,66,67,68,
5798 69,70,71,72,
5799 -1
5800 };
5801
5802 static TABPANEL keyboard_control_tabs[] =
5803 {
5804 // (text)
5805 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5806 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5807 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5808 { NULL, 0, NULL, 0, NULL }
5809 };
5810
5811 static DIALOG keyboard_control_dlg[] =
5812 {
5813 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5814 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5815 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5816 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5817 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5818 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5819 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5820 // Keys
5821 // 6
5822 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5823 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5824 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5825 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5826 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5827 // 11
5828 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5829 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5830 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5831 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5832 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5833 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5834 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5835 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5836 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5837 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5838 // 21
5839 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5840 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5841 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5842 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5843 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5844 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5845 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5846 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5847 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5848 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5849 // 31
5850 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5851 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5852 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5853 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5854 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5855 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5856 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5857 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5858 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5859 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5860 // Dirs
5861 // 41
5862 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5863 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5864 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5865 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5866 // 45
5867 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5868 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5869 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5870 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5871 // 49
5872 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5873 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5874 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5875 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5876 // 53
5877 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5878 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5879 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5880 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5881 // Mods
5882 // 57
5883 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5884 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5885 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5886 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5887 // 61
5888 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5889 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5890 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5891 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5892 // 65
5893 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5894 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5895 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5896 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5897 // 69
5898 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5899 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5900 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5901 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5902 // 73
5903 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5904 };
5905
5906 /*
5907 int32_t midi_dp[3] = {0,147,104};
5908 int32_t digi_dp[3] = {1,147,120};
5909 int32_t pan_dp[3] = {0,147,136};
5910 int32_t buf_dp[3] = {0,147,152};
5911 */
5912 int32_t midi_dp[3] = {0,0,0};
5913 int32_t digi_dp[3] = {1,0,0};
5914 int32_t emus_dp[3] = {2,0,0};
5915 int32_t buf_dp[3] = {0,0,0};
5916 int32_t sfx_dp[3] = {3,0,0};
5917 int32_t pan_dp[3] = {0,0,0};
5918
5919 static DIALOG sound_dlg[] =
5920 {
5921 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5922 117 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5923 117 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5924 117 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5925 117 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5926 117 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5927 117 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5928 117 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5929 117 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_b, NULL, NULL },
5930 117 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5931 117 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_m, NULL, NULL },
5932 // 10
5933 117 { jwin_rtext_proc, 190, 104, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5934 117 { jwin_rtext_proc, 190, 120, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5935 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5936 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5937 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5938 117 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5939 117 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, digi_dp },
5940 117 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5941 117 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 127, 0, NULL, (void *) set_buf, buf_dp },
5942 117 { jwin_slider_proc, 196, 104, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5943 //20
5944 117 { jwin_slider_proc, 196, 120, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5945 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5946 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5947 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5948 117 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Master MIDI Volume", NULL, NULL },
5949 117 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Master Digi Volume", NULL, NULL },
5950 117 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Enhanced Music Volume", NULL, NULL },
5951 117 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Enhanced Music Buffer", NULL, NULL },
5952 117 { jwin_text_proc, 17, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5953 117 { jwin_text_proc, 17, 120, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5954 //30
5955 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5956 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5957 117 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5958 117 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5959 };
5960
5961 char zc_builddate[80];
5962 char zc_aboutstr[80];
5963
5964 static DIALOG about_dlg[] =
5965 {
5966 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5967 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5968 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5969 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5970 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5971 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5972 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5973 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5974 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5975 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5976 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5977 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5978 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5979 };
5980
5981
5982 static DIALOG quest_dlg[] =
5983 {
5984 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5985 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5986 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5987 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5988 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5989 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5990 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5991 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5992 { jwin_text_proc, 184, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5993 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5994 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5995 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5996 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5997 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5998 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5999 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6000 };
6001
6002 static DIALOG triforce_dlg[] =
6003 {
6004 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6005 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
6006 // 1
6007 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
6008 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
6009 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
6010 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
6011 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
6012 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
6013 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
6014 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
6015 // 9
6016 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6017 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6018 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6019 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6020 };
6021
6022 bool zc_getname(const char *prompt,const char *ext,EXT_LIST *list,const char *def,bool usefilename)
6023 {
6024 go();
6025 int32_t ret=0;
6026 ret = zc_getname_nogo(prompt,ext,list,def,usefilename);
6027 comeback();
6028 return ret != 0;
6029 }
6030
6031
6032 bool zc_getname_nogo(const char *prompt,const char *ext,EXT_LIST *list,const char *def,bool usefilename)
6033 {
6034 if(def!=modulepath)
6035 strcpy(modulepath,def);
6036
6037 if(!usefilename)
6038 {
6039 int32_t i=(int32_t)strlen(modulepath);
6040
6041 while(i>=0 && modulepath[i]!='\\' && modulepath[i]!='/')
6042 modulepath[i--]=0;
6043 }
6044
6045 // int32_t ret = file_select_ex(prompt,modulepath,ext,255,-1,-1);
6046 int32_t ret=0;
6047 int32_t sel=0;
6048
6049 if(list==NULL)
6050 {
6051 ret = jwin_file_select_ex(prompt,modulepath,ext,2048,-1,-1,get_zc_font(font_lfont));
6052 }
6053 else
6054 {
6055 ret = jwin_file_browse_ex(prompt, modulepath, list, &sel, 2048, -1, -1, get_zc_font(font_lfont));
6056 }
6057
6058 return ret!=0;
6059 }
6060
6061 int32_t onToggleRecordingNewSaves()
6062 {
6063 if (zc_get_config("zeldadx", "replay_new_saves", false))
6064 {
6065 zc_set_config("zeldadx", "replay_new_saves", false);
6066 }
6067 else
6068 {
6069 zc_set_config("zeldadx", "replay_new_saves", true);
6070 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
6071 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6072 }
6073 return D_O_K;
6074 }
6075
6076 int32_t onToggleSnapshotAllFrames()
6077 {
6078 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
6079 return D_O_K;
6080 }
6081
6082 int32_t onStopReplayOrRecord()
6083 {
6084 if (replay_is_replaying())
6085 {
6086 replay_quit();
6087 }
6088 else if (replay_get_mode() == ReplayMode::Record)
6089 {
6090 if (!replay_get_meta_bool("test_mode"))
6091 {
6092 jwin_alert("Recording", "You cannot stop recording a save file.",
6093 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6094 return D_CLOSE;
6095 }
6096
6097 if (jwin_alert("Stop Recording",
6098 "Save replay to disk and stop recording?",
6099 "This will stop the recording.",
6100 NULL,
6101 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6102 return D_CLOSE;
6103
6104 replay_save();
6105 replay_stop();
6106 }
6107 return D_O_K;
6108 }
6109
6110 static int32_t handle_on_load_replay(ReplayMode mode)
6111 {
6112 if (Playing)
6113 {
6114 if (jwin_alert("Replay - Warning!",
6115 "Loading a replay will exit the current game.",
6116 "All unsaved progress will be lost.",
6117 "Do you wish to continue?",
6118 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6119 return D_CLOSE;
6120 }
6121
6122 std::string mode_string = replay_mode_to_string(mode);
6123 mode_string[0] = std::toupper(mode_string[0]);
6124
6125 std::string line_1 = "Select a replay file to play back.";
6126 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
6127 std::string line_3 = "You can stop the replay and take over manually any time.";
6128 if (mode == ReplayMode::Update)
6129 {
6130 line_1 = "Select a replay file to update.";
6131 line_2 = "WARNING: be sure to back up the zplay file";
6132 line_3 = "and verify that the updated replay works as expected!";
6133 }
6134
6135 if (jwin_alert(mode_string.c_str(),
6136 line_1.c_str(),
6137 line_2.c_str(),
6138 line_3.c_str(),
6139 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
6140 {
6141 char replay_path[2048];
6142 strcpy(replay_path, "replays/");
6143 if (jwin_file_select_ex(
6144 fmt::format("Load Replay ({})", REPLAY_EXTENSION).c_str(),
6145 replay_path, REPLAY_EXTENSION.c_str(), 2048, -1, -1, get_zc_font(font_lfont)) == 0)
6146 return D_CLOSE;
6147
6148 replay_quit();
6149 load_replay_file_deferred(mode, replay_path);
6150 Quit = qRESET;
6151 return D_CLOSE;
6152 }
6153 return D_O_K;
6154 }
6155
6156 int32_t onLoadReplay()
6157 {
6158 return handle_on_load_replay(ReplayMode::Replay);
6159 }
6160
6161 int32_t onLoadReplayAssert()
6162 {
6163 return handle_on_load_replay(ReplayMode::Assert);
6164 }
6165
6166 int32_t onLoadReplayUpdate()
6167 {
6168 return handle_on_load_replay(ReplayMode::Update);
6169 }
6170
6171 int32_t onSaveReplay()
6172 {
6173 if (replay_get_mode() == ReplayMode::Record)
6174 {
6175 if (!replay_get_meta_bool("test_mode"))
6176 {
6177 if (jwin_alert("Save Replay",
6178 "This will save a copy of the replay up to this point.",
6179 "The official replay file will be untouched.",
6180 "Do you wish to continue?",
6181 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
6182 return D_CLOSE;
6183
6184 char replay_path[2048];
6185 strcpy(replay_path, replay_get_replay_path().string().c_str());
6186 if (jwin_file_select_ex(
6187 fmt::format("Save Replay ({})", REPLAY_EXTENSION).c_str(),
6188 replay_path, REPLAY_EXTENSION.c_str(), 2048, -1, -1, get_zc_font(font_lfont)) == 0)
6189 return D_CLOSE;
6190
6191 if (fileexists(replay_path))
6192 {
6193 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
6194 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6195 return D_CLOSE;
6196 }
6197
6198 replay_save(replay_path);
6199 }
6200 else
6201 {
6202 replay_save();
6203 }
6204 }
6205 return D_O_K;
6206 }
6207
6208 static MENU replay_menu[] =
6209 {
6210 { (char *)"Record new saves", onToggleRecordingNewSaves, NULL, 0, NULL },
6211 { (char *)"Stop replay", onStopReplayOrRecord, NULL, 0, NULL },
6212 { (char *)"Load replay", onLoadReplay, NULL, 0, NULL },
6213 { (char *)"Load replay (assert)", onLoadReplayAssert, NULL, 0, NULL },
6214 { (char *)"Load replay (update)", onLoadReplayUpdate, NULL, 0, NULL },
6215 { (char *)"Save replay", onSaveReplay, NULL, 0, NULL },
6216 { (char *)"Enable snapshot all frames", onToggleSnapshotAllFrames,NULL, 0, NULL },
6217
6218 { NULL, NULL, NULL, 0, NULL }
6219 };
6220
6221 static DIALOG credits_dlg[] =
6222 {
6223 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6224 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6225 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6226 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6227 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6228 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6229 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6230 };
6231
6232 117 static ListData dmap_list(dmaplist, &font);
6233
6234 static DIALOG goto_dlg[] =
6235 {
6236 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6237 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6238 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6239 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6240 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6241 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6242 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6243 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6244 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6245 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6246 };
6247
6248 int32_t onGoTo()
6249 {
6250 bool music = false;
6251 music = music;
6252 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6253
6254 goto_dlg[0].dp2=get_zc_font(font_lfont);
6255 goto_dlg[4].d2=cheat_goto_dmap;
6256 goto_dlg[6].dp=cheat_goto_screen_str;
6257
6258 clear_keybuf();
6259
6260 large_dialog(goto_dlg);
6261
6262 if(do_zqdialog(goto_dlg,4)==1)
6263 {
6264 // dmap, screen
6265 cheats_enqueue(Cheat::GoTo, goto_dlg[4].d2, zc_min(zc_xtoi(cheat_goto_screen_str),0x7F));
6266 };
6267
6268 return D_O_K;
6269 }
6270
6271 int32_t onGoToComplete()
6272 {
6273 if(!Playing)
6274 {
6275 return D_O_K;
6276 }
6277
6278 enter_sys_pal();
6279 music_pause();
6280 pause_all_sfx();
6281 onGoTo();
6282 eat_buttons();
6283
6284 zc_readrawkey(KEY_ESC);
6285
6286 exit_sys_pal();
6287 music_resume();
6288 resume_all_sfx();
6289 return D_O_K;
6290 }
6291
6292 int32_t onCredits()
6293 {
6294 return D_O_K;
6295 }
6296
6297 const char *midilist(int32_t index, int32_t *list_size)
6298 {
6299 if(index<0)
6300 {
6301 *list_size=0;
6302
6303 for(int32_t i=0; i<MAXMIDIS; i++)
6304 if(tunes[i].data)
6305 ++(*list_size);
6306
6307 return NULL;
6308 }
6309
6310 int32_t i=0,m=0;
6311
6312 while(m<=index && i<=MAXMIDIS)
6313 {
6314 if(tunes[i].data)
6315 ++m;
6316
6317 ++i;
6318 }
6319
6320 --i;
6321
6322 if(i==MAXMIDIS && m<index)
6323 return "(null)";
6324
6325 return tunes[i].title;
6326 }
6327
6328 /* ------- MIDI info stuff -------- */
6329
6330 char *text;
6331 midi_info *zmi;
6332 bool dialog_running;
6333 bool listening;
6334
6335 void get_info(int32_t index);
6336
6337 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6338 {
6339 int32_t d2 = d->d2;
6340 int32_t ret = jwin_droplist_proc(msg,d,c);
6341
6342 if(d2!=d->d2)
6343 {
6344 get_info(d->d2);
6345 }
6346
6347 return ret;
6348 }
6349
6350 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6351 {
6352 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6353
6354 int32_t ret = jwin_button_proc(msg,d,c);
6355
6356 if(ret == D_CLOSE)
6357 {
6358 // get current midi index
6359 int32_t index = (d+(d->d1))->d2;
6360 int32_t i=0, m=0;
6361
6362 while(m<=index && i<=MAXMIDIS)
6363 {
6364 if(tunes[i].data)
6365 ++m;
6366
6367 ++i;
6368 }
6369
6370 --i;
6371 jukebox(i);
6372 listening = true;
6373 ret = D_O_K;
6374 }
6375
6376 return ret;
6377 }
6378
6379 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6380 {
6381 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6382
6383 int32_t ret = jwin_button_proc(msg,d,c);
6384
6385 if(ret == D_CLOSE)
6386 {
6387 // get current midi index
6388 int32_t index = (d+(d->d1))->d2;
6389 int32_t i=0, m=0;
6390
6391 while(m<=index && i<=MAXMIDIS)
6392 {
6393 if(tunes[i].data)
6394 ++m;
6395
6396 ++i;
6397 }
6398
6399 --i;
6400
6401 // get file name
6402
6403 int32_t sel=0;
6404 //struct ffblk f;
6405 char title[40] = "Save MIDI: ";
6406 char fname[2048];
6407 memset(fname,0,2048);
6408 static EXT_LIST list[] =
6409 {
6410 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6411 { (char *)"HTML files (*.html, *.html)", (char *)"htm html" },
6412 { NULL, NULL }
6413 };
6414
6415 strcpy(title+11, tunes[i].title);
6416 title[39] = '\0';
6417
6418 if(jwin_file_browse_ex(title, fname, list, &sel, 2048, -1, -1, get_zc_font(font_lfont))==0)
6419 goto done;
6420
6421 if(exists(fname))
6422 {
6423 if(jwin_alert(title, fname, "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6424 goto done;
6425 }
6426
6427 // save midi i
6428
6429 if(save_midi(fname, (MIDI*)tunes[i].data) != 0)
6430 jwin_alert(title, "Error saving MIDI to", fname, NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6431
6432 done:
6433 chop_path(fname);
6434 ret = D_REDRAW;
6435 }
6436
6437 return ret;
6438 }
6439
6440 117 static ListData midi_list(midilist, &font);
6441
6442 static DIALOG midi_dlg[] =
6443 {
6444 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6445 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6446 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6447 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6448 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6449 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6450 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6451 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6452 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6453 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6454 };
6455
6456 void get_info(int32_t index)
6457 {
6458 int32_t i=0, m=0;
6459
6460 while(m<=index && i<=MAXMIDIS)
6461 {
6462 if(tunes[i].data)
6463 ++m;
6464
6465 ++i;
6466 }
6467
6468 --i;
6469
6470 if(i==MAXMIDIS && m<index)
6471 strcpy(text,"(null)");
6472 else
6473 {
6474 get_midi_info((MIDI*)tunes[i].data,zmi);
6475 get_midi_text((MIDI*)tunes[i].data,zmi,text);
6476 }
6477
6478 midi_dlg[0].dp2=get_zc_font(font_lfont);
6479 midi_dlg[3].dp = text;
6480 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6481 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6482
6483 if(dialog_running)
6484 {
6485 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6486 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6487 }
6488 }
6489
6490 int32_t onMIDICredits()
6491 {
6492 text = (char*)malloc(4096);
6493 zmi = (midi_info*)malloc(sizeof(midi_info));
6494
6495 if(!text || !zmi)
6496 {
6497 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6498 return D_O_K;
6499 }
6500
6501 bool do_pause_midi = midi_pos >= 0 && currmidi;
6502 auto restore_midi = currmidi;
6503 if(do_pause_midi)
6504 {
6505 paused_midi_pos = midi_pos;
6506 stop_midi();
6507 midi_suspended = midissuspHALTED;
6508 }
6509
6510 midi_dlg[0].dp2=get_zc_font(font_lfont);
6511 midi_dlg[2].d1 = 0;
6512 midi_dlg[2].d2 = 0;
6513 midi_dlg[4].flags = D_EXIT;
6514 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6515
6516 listening = false;
6517 dialog_running=false;
6518 get_info(0);
6519
6520 dialog_running=true;
6521
6522 large_dialog(midi_dlg);
6523
6524 do_zqdialog(midi_dlg,0);
6525 dialog_running=false;
6526
6527 if(listening)
6528 music_stop();
6529
6530 if(do_pause_midi)
6531 {
6532 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6533 midi_suspended = midissuspRESUME;
6534 currmidi = restore_midi;
6535 midi_pos = paused_midi_pos;
6536 }
6537
6538 if(text) free(text);
6539 if(zmi) free(zmi);
6540 return D_O_K;
6541 }
6542
6543 int32_t onAbout()
6544 {
6545 char buf1[80]={0};
6546 std::ostringstream oss;
6547 sprintf(buf1,"%s, Version: %s", ZC_PLAYER_NAME,ZC_PLAYER_V);
6548 oss << buf1 << '\n';
6549 sprintf(buf1, "%s", ALPHA_VER_STR);
6550 oss << buf1 << '\n';
6551 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6552 oss << buf1 << '\n';
6553 sprintf(buf1, "Built By: %s", DEV_SIGNOFF);
6554 oss << buf1 << '\n';
6555 sprintf(buf1, "Tag: %s", getReleaseTag());
6556 oss << buf1 << '\n';
6557
6558 InfoDialog("About ZC", oss.str()).show();
6559 return D_O_K;
6560 }
6561
6562 int32_t onQuest()
6563 {
6564 char fname[100];
6565 strcpy(fname, get_filename(qstpath));
6566 quest_dlg[0].dp2=get_zc_font(font_lfont);
6567 quest_dlg[1].dp = fname;
6568
6569 if(QHeader.quest_number==0)
6570 sprintf(str_a,"Custom");
6571 else
6572 sprintf(str_a,"%d",QHeader.quest_number);
6573
6574 sprintf(str_s,"%s",VerStr(QHeader.zelda_version));
6575
6576 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6577 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6578
6579 large_dialog(quest_dlg);
6580
6581 do_zqdialog(quest_dlg, 0);
6582 return D_O_K;
6583 }
6584
6585 void call_vidmode_dlg();
6586 int32_t onVidMode()
6587 {
6588 call_vidmode_dlg();
6589 return D_O_K;
6590 }
6591
6592 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6593 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6594 //Added an extra statement, so that if the key is cleared to 0, the cleared
6595 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6596
6597 void load_ukeys(int32_t* arr)
6598 {
6599 arr[ukey_a] = Akey;
6600 arr[ukey_b] = Bkey;
6601 arr[ukey_s] = Skey;
6602 arr[ukey_l] = Lkey;
6603 arr[ukey_r] = Rkey;
6604 arr[ukey_p] = Pkey;
6605 arr[ukey_ex1] = Exkey1;
6606 arr[ukey_ex2] = Exkey2;
6607 arr[ukey_ex3] = Exkey3;
6608 arr[ukey_ex4] = Exkey4;
6609 arr[ukey_du] = DUkey;
6610 arr[ukey_dd] = DDkey;
6611 arr[ukey_dl] = DLkey;
6612 arr[ukey_dr] = DRkey;
6613 arr[ukey_mod1a] = cheat_modifier_keys[0];
6614 arr[ukey_mod1b] = cheat_modifier_keys[1];
6615 arr[ukey_mod2a] = cheat_modifier_keys[2];
6616 arr[ukey_mod2b] = cheat_modifier_keys[3];
6617 };
6618
6619 static const char* ukey_names[] = {
6620 "A", "B", "Start", "L", "R", "Map",
6621 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6622 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6623 "Cheat Mod R1", "Cheat Mod R2",
6624 };
6625 std::string get_ukey_name(int32_t k)
6626 {
6627 if (k < num_ukey) return ukey_names[k];
6628 return "";
6629 }
6630
6631 int32_t onKeyboard()
6632 {
6633 int32_t a = Akey;
6634 int32_t b = Bkey;
6635 int32_t s = Skey;
6636 int32_t l = Lkey;
6637 int32_t r = Rkey;
6638 int32_t p = Pkey;
6639 int32_t ex1 = Exkey1;
6640 int32_t ex2 = Exkey2;
6641 int32_t ex3 = Exkey3;
6642 int32_t ex4 = Exkey4;
6643 int32_t du = DUkey;
6644 int32_t dd = DDkey;
6645 int32_t dl = DLkey;
6646 int32_t dr = DRkey;
6647 int32_t mod1a = cheat_modifier_keys[0];
6648 int32_t mod1b = cheat_modifier_keys[1];
6649 int32_t mod2a = cheat_modifier_keys[2];
6650 int32_t mod2b = cheat_modifier_keys[3];
6651 bool done=false;
6652 int32_t ret;
6653
6654 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6655
6656 large_dialog(keyboard_control_dlg);
6657
6658 while(!done)
6659 {
6660 ret = do_zqdialog(keyboard_control_dlg,3);
6661
6662 if(ret==3) // OK
6663 {
6664 int32_t ukeys[num_ukey];
6665 load_ukeys(ukeys);
6666 std::vector<std::string> uniqueError;
6667 for(int32_t q = 0; q < num_ukey; ++q)
6668 {
6669 for(int32_t p = q+1; p < num_ukey; ++p)
6670 {
6671 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6672 {
6673 char buf[64];
6674 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6675 std::string str(buf);
6676 uniqueError.push_back(str);
6677 }
6678 }
6679 }
6680 if(uniqueError.size() == 0)
6681 {
6682 done = true;
6683 save_control_configs(true);
6684 }
6685 else
6686 {
6687 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6688 box_out("Cannot have duplicate keybinds!"); box_eol();
6689 for(std::vector<std::string>::iterator it = uniqueError.begin();
6690 it != uniqueError.end(); ++it)
6691 {
6692 box_out((*it).c_str()); box_eol();
6693 }
6694 box_end(true);
6695 }
6696 }
6697 else // Cancel
6698 {
6699 Akey = a;
6700 Bkey = b;
6701 Skey = s;
6702 Lkey = l;
6703 Rkey = r;
6704 Pkey = p;
6705 Exkey1 = ex1;
6706 Exkey2 = ex2;
6707 Exkey3 = ex3;
6708 Exkey4 = ex4;
6709 DUkey = du;
6710 DDkey = dd;
6711 DLkey = dl;
6712 DRkey = dr;
6713 cheat_modifier_keys[0] = mod1a;
6714 cheat_modifier_keys[1] = mod1b;
6715 cheat_modifier_keys[2] = mod2a;
6716 cheat_modifier_keys[3] = mod2b;
6717
6718 done=true;
6719 }
6720
6721 rest(1);
6722 }
6723
6724 return D_O_K;
6725 }
6726
6727 int32_t onGamepad()
6728 {
6729 if (al_get_num_joysticks() == 0)
6730 {
6731 InfoDialog("ZC", "No gamepads detected.").show();
6732 return D_O_K;
6733 }
6734
6735 int32_t a = Abtn;
6736 int32_t b = Bbtn;
6737 int32_t s = Sbtn;
6738 int32_t l = Lbtn;
6739 int32_t r = Rbtn;
6740 int32_t m = Mbtn;
6741 int32_t p = Pbtn;
6742 int32_t ex1 = Exbtn1;
6743 int32_t ex2 = Exbtn2;
6744 int32_t ex3 = Exbtn3;
6745 int32_t ex4 = Exbtn4;
6746 int32_t up = DUbtn;
6747 int32_t down = DDbtn;
6748 int32_t left = DLbtn;
6749 int32_t right = DRbtn;
6750 int32_t joy = joystick_index;
6751 int32_t stick_1 = js_stick_1_x_stick;
6752 int32_t stick_2 = js_stick_2_x_stick;
6753
6754 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6755 if(analog_movement)
6756 gamepad_dlg[56].flags|=D_SELECTED;
6757 else
6758 gamepad_dlg[56].flags&=~D_SELECTED;
6759
6760 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6761 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6762 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6763 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6764 // requires remapping every time.
6765 if (joystick_index >= al_get_num_joysticks())
6766 joystick_index = 0;
6767 gamepad_dlg[61].d2 = joystick_index;
6768
6769 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6770 if (!gamepad_dlg_cur_joystick)
6771 {
6772 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6773 return D_CLOSE;
6774 }
6775
6776 large_dialog(gamepad_dlg);
6777
6778 int32_t ret = do_zqdialog(gamepad_dlg,4);
6779
6780 if(ret == 4) //OK
6781 {
6782 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6783 joystick_index = gamepad_dlg[61].d2;
6784 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6785 if (!gamepad_dlg_cur_joystick)
6786 {
6787 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6788 return D_CLOSE;
6789 }
6790 js_stick_1_y_stick = js_stick_1_x_stick;
6791 js_stick_2_y_stick = js_stick_2_x_stick;
6792 save_control_configs(false);
6793 }
6794 else //Cancel
6795 {
6796 Abtn = a;
6797 Bbtn = b;
6798 Sbtn = s;
6799 Lbtn = l;
6800 Rbtn = r;
6801 Mbtn = m;
6802 Pbtn = p;
6803 Exbtn1 = ex1;
6804 Exbtn2 = ex2;
6805 Exbtn3 = ex3;
6806 Exbtn4 = ex4;
6807 DUbtn = up;
6808 DDbtn = down;
6809 DLbtn = left;
6810 DRbtn = right;
6811 joystick_index = joy;
6812 js_stick_1_x_stick = stick_1;
6813 js_stick_2_x_stick = stick_2;
6814 }
6815
6816 return D_O_K;
6817 }
6818
6819 int32_t onCheatKeys()
6820 {
6821 int32_t oldcheats[Cheat::Last][2];
6822 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6823
6824 bool done=false;
6825
6826 while(!done)
6827 {
6828 bool confirm = false;
6829 CheatKeysDialog(&confirm).show();
6830 if(confirm) // OK
6831 {
6832 std::vector<std::string> uniqueError;
6833 char buf[512];
6834 for(size_t q = 1; q < Cheat::Last; ++q)
6835 {
6836 if(cheatkeys[q][1] && !cheatkeys[q][0])
6837 {
6838 cheatkeys[q][0] = cheatkeys[q][1];
6839 cheatkeys[q][1] = 0;
6840 }
6841 }
6842 for(size_t q = 1; q < Cheat::Last; ++q)
6843 {
6844 if(!bindable_cheat((Cheat)q)) continue;
6845 for(size_t p = q+1; p < Cheat::Last; ++p)
6846 {
6847 if(!bindable_cheat((Cheat)p)) continue;
6848 for(size_t q2 = 0; q2 <= 1; ++q2)
6849 for(size_t p2 = 0; p2 <= 1; ++p2)
6850 {
6851 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6852 {
6853 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6854 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6855 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6856 get_keystr(cheatkeys[q][q2])));
6857 }
6858 }
6859 }
6860 }
6861 if(uniqueError.size() == 0)
6862 {
6863 done = true;
6864 save_cheatkeys();
6865 }
6866 else
6867 {
6868 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6869 box_out("Cannot have duplicate keybinds!"); box_eol();
6870 for(std::vector<std::string>::iterator it = uniqueError.begin();
6871 it != uniqueError.end(); ++it)
6872 {
6873 box_out((*it).c_str()); box_eol();
6874 }
6875 box_end(true);
6876 }
6877 }
6878 else // Cancel
6879 {
6880 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6881 done=true;
6882 }
6883 rest(1);
6884 }
6885
6886 return D_O_K;
6887 }
6888
6889 int32_t onSound()
6890 {
6891 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6892 {
6893 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6894 {
6895 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6896 }
6897 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6898 {
6899 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6900 }
6901 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6902 {
6903 emusic_volume = (int32_t)FFCore.usr_music_volume;
6904 }
6905 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6906 {
6907 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6908 }
6909 }
6910 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6911 {
6912 pan_style = (int32_t)FFCore.usr_panstyle;
6913 }
6914
6915 int32_t m = midi_volume;
6916 int32_t d = digi_volume;
6917 int32_t e = emusic_volume;
6918 int32_t b = zcmusic_bufsz;
6919 int32_t s = sfx_volume;
6920 int32_t p = pan_style;
6921 pan_style = vbound(pan_style,0,3);
6922
6923 sound_dlg[0].dp2=get_zc_font(font_lfont);
6924
6925 large_dialog(sound_dlg);
6926
6927 midi_dp[1] = sound_dlg[6].x;
6928 midi_dp[2] = sound_dlg[6].y;
6929 digi_dp[1] = sound_dlg[7].x;
6930 digi_dp[2] = sound_dlg[7].y;
6931 emus_dp[1] = sound_dlg[8].x;
6932 emus_dp[2] = sound_dlg[8].y;
6933 buf_dp[1] = sound_dlg[9].x;
6934 buf_dp[2] = sound_dlg[9].y;
6935 sfx_dp[1] = sound_dlg[10].x;
6936 sfx_dp[2] = sound_dlg[10].y;
6937 pan_dp[1] = sound_dlg[11].x;
6938 pan_dp[2] = sound_dlg[11].y;
6939 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6940 sound_dlg[16].d2 = (digi_volume==255) ? 32 : digi_volume>>3;
6941 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6942 sound_dlg[18].d2 = zcmusic_bufsz;
6943 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6944 sound_dlg[20].d2 = pan_style;
6945
6946 int32_t ret = do_zqdialog(sound_dlg,1);
6947
6948 if(ret==2)
6949 {
6950 master_volume(digi_volume,midi_volume);
6951 if (zcmusic)
6952 zcmusic_set_volume(zcmusic, emusic_volume);
6953
6954 int32_t temp_volume = sfx_volume;
6955 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6956 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6957 for(int32_t i=0; i<WAV_COUNT; ++i)
6958 {
6959 //allegro assertion fails when passing in -1 as voice -DD
6960 if(sfx_voice[i] > 0)
6961 voice_set_volume(sfx_voice[i], temp_volume);
6962 }
6963 zc_set_config(sfx_sect,"digi",digi_volume);
6964 zc_set_config(sfx_sect,"midi",midi_volume);
6965 zc_set_config(sfx_sect,"sfx",sfx_volume);
6966 zc_set_config(sfx_sect,"emusic",emusic_volume);
6967 zc_set_config(sfx_sect,"pan",pan_style);
6968 zc_set_config(sfx_sect,"zcmusic_bufsz",zcmusic_bufsz);
6969 }
6970 else
6971 {
6972 midi_volume = m;
6973 digi_volume = d;
6974 emusic_volume = e;
6975 zcmusic_bufsz = b;
6976 sfx_volume = s;
6977 pan_style = p;
6978 }
6979
6980 return D_O_K;
6981 }
6982
6983 int32_t queding(char const* s1, char const* s2, char const* s3)
6984 {
6985 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6986 }
6987
6988 int32_t onQuit()
6989 {
6990 if(Playing)
6991 {
6992 int32_t ret=0;
6993
6994 if(get_qr(qr_NOCONTINUE))
6995 {
6996 if(standalone_mode)
6997 {
6998 ret=queding("End current game?",
6999 "The continue screen is disabled; the game",
7000 "will be reloaded from the last save.");
7001 }
7002 else
7003 {
7004 ret=queding("End current game?",
7005 "The continue screen is disabled. You will",
7006 "be returned to the file select screen.");
7007 }
7008 }
7009 else
7010 ret=queding("End current game?",NULL,NULL);
7011
7012 if(ret==1)
7013 {
7014 disableClickToFreeze=false;
7015 Quit=qQUIT;
7016
7017 // Trying to evade a door repair charge?
7018 if(repaircharge)
7019 {
7020 game->change_drupy(-repaircharge);
7021 repaircharge=0;
7022 }
7023
7024 return D_CLOSE;
7025 }
7026 }
7027
7028 return D_O_K;
7029 }
7030
7031 int32_t onTryQuitMenu()
7032 {
7033 return onTryQuit(true);
7034 }
7035
7036 int32_t onTryQuit(bool inMenu)
7037 {
7038 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
7039 {
7040 if(active_cutscene.can_f6())
7041 {
7042 if(get_qr(qr_OLD_F6))
7043 {
7044 if(inMenu) onQuit();
7045 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
7046 }
7047 else
7048 {
7049 disableClickToFreeze=false;
7050 GameFlags |= GAMEFLAG_TRYQUIT;
7051 }
7052 return D_CLOSE;
7053 }
7054 else active_cutscene.error();
7055 }
7056
7057 return D_O_K;
7058 }
7059
7060 int32_t onReset()
7061 {
7062 if(queding(" Reset system? ",NULL,NULL)==1)
7063 {
7064 disableClickToFreeze=false;
7065 Quit=qRESET;
7066 replay_quit();
7067 return D_CLOSE;
7068 }
7069
7070 return D_O_K;
7071 }
7072
7073 int32_t onExit()
7074 {
7075 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
7076 {
7077 Quit=qEXIT;
7078 return D_CLOSE;
7079 }
7080
7081 return D_O_K;
7082 }
7083
7084 int32_t onDebug()
7085 {
7086 if(debug_enabled)
7087 set_debug(!get_debug());
7088 return D_O_K;
7089 }
7090
7091 int32_t onHeartBeep()
7092 {
7093 heart_beep=!heart_beep;
7094 zc_set_config(cfg_sect,"heart_beep",heart_beep);
7095 return D_O_K;
7096 }
7097
7098 int32_t onSaveIndicator()
7099 {
7100 use_save_indicator = use_save_indicator ? 0 : 1;
7101 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
7102 return D_O_K;
7103 }
7104
7105 int32_t onEpilepsy()
7106 {
7107 if(jwin_alert3(
7108 "Epilepsy Flash Reduction",
7109 "Enabling this will reduce the intensity of flashing and screen wave effects.",
7110 "Disabling this will restore standard flash and wavy behaviour.",
7111 "Proceed?",
7112 "&Yes",
7113 "&No",
7114 NULL,
7115 'y',
7116 'n',
7117 0,
7118 get_zc_font(font_lfont)) == 1)
7119 {
7120 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
7121 zc_set_config("zeldadx","checked_epilepsy",1);
7122 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
7123 }
7124 return D_O_K;
7125 }
7126
7127 bool rc = false;
7128
7129 static DIALOG getnum_dlg[] =
7130 {
7131 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
7132 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
7133 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
7134 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
7135 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7136 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7137 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7138 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7139 };
7140
7141 int32_t getnumber(const char *prompt,int32_t initialval)
7142 {
7143 char buf[20];
7144 sprintf(buf,"%d",initialval);
7145 getnum_dlg[0].dp=(void *)prompt;
7146 getnum_dlg[0].dp2=get_zc_font(font_lfont);
7147 getnum_dlg[2].dp=buf;
7148
7149 large_dialog(getnum_dlg);
7150
7151 if(do_zqdialog(getnum_dlg,2)==3)
7152 return atoi(buf);
7153
7154 return initialval;
7155 }
7156
7157 int32_t onLife()
7158 {
7159 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
7160 cheats_enqueue(Cheat::Life, value);
7161 return D_O_K;
7162 }
7163
7164 int32_t onHeartC()
7165 {
7166 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
7167 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
7168 cheats_enqueue(Cheat::MaxLife, max_life);
7169 cheats_enqueue(Cheat::Life, life);
7170 return D_O_K;
7171 }
7172
7173 int32_t onMagicC()
7174 {
7175 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
7176 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
7177 cheats_enqueue(Cheat::MaxMagic, max_magic);
7178 cheats_enqueue(Cheat::Magic, magic);
7179 return D_O_K;
7180 }
7181
7182 int32_t onRupies()
7183 {
7184 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
7185 cheats_enqueue(Cheat::Rupies, value);
7186 return D_O_K;
7187 }
7188
7189 int32_t onMaxBombs()
7190 {
7191 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
7192 cheats_enqueue(Cheat::MaxBombs, value);
7193 cheats_enqueue(Cheat::Bombs, value);
7194 return D_O_K;
7195 }
7196
7197 int32_t onRefillLife()
7198 {
7199 cheats_enqueue(Cheat::Life, game->get_maxlife());
7200 return D_O_K;
7201 }
7202 int32_t onRefillMagic()
7203 {
7204 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
7205 return D_O_K;
7206 }
7207 int32_t onClock()
7208 {
7209 cheats_enqueue(Cheat::Clock);
7210 return D_O_K;
7211 }
7212
7213 int32_t onQstPath()
7214 {
7215 char path[2048];
7216
7217 chop_path(qstdir);
7218 strcpy(path,qstdir);
7219
7220 go();
7221
7222 if(jwin_dfile_select_ex("Quest File Directory", path, "qst", 2048, -1, -1, get_zc_font(font_lfont)))
7223 {
7224 chop_path(path);
7225 fix_filename_case(path);
7226 fix_filename_slashes(path);
7227 strcpy(qstdir,path);
7228 strcpy(qstpath,qstdir);
7229 zc_set_config("zeldadx","quest_dir",qstdir);
7230 flush_config_file();
7231 }
7232
7233 comeback();
7234 return D_O_K;
7235 }
7236
7237 #include "dialog/cheat_dialog.h"
7238 int32_t onCheat()
7239 {
7240 call_setcheat_dialog();
7241 game->set_cheat(maxcheat);
7242 if(cheat) game->did_cheat(true);
7243 return D_O_K;
7244 }
7245
7246 int32_t onCheatRupies()
7247 {
7248 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7249 return D_O_K;
7250 }
7251
7252 int32_t onCheatArrows()
7253 {
7254 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7255 return D_O_K;
7256 }
7257
7258 int32_t onCheatBombs()
7259 {
7260 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7261 return D_O_K;
7262 }
7263
7264 // *** screen saver
7265
7266 9287211 int32_t after_time()
7267 {
7268
1/2
✓ Branch 0 taken 9287211 times.
✗ Branch 1 not taken.
9287211 if(ss_enable == 0)
7269 return INT_MAX;
7270
7271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
9287211 if(ss_after <= 0)
7272 return 5 * 60;
7273
7274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
9287211 if(ss_after <= 3)
7275 return ss_after * 15 * 60;
7276
7277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287211 times.
9287211 if(ss_after <= 13)
7278 return (ss_after - 3) * 60 * 60;
7279
7280 9287211 return MAX_IDLE + 1;
7281 9287211 }
7282
7283 static const char *after_str[15] =
7284 {
7285 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7286 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7287 "Never"
7288 };
7289
7290 const char *after_list(int32_t index, int32_t *list_size)
7291 {
7292 if(index < 0)
7293 {
7294 *list_size = 15;
7295 return NULL;
7296 }
7297
7298 return after_str[index];
7299 }
7300
7301 117 static ListData after__list(after_list, &font);
7302
7303 static DIALOG scrsaver_dlg[] =
7304 {
7305 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7306 117 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7307 117 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7308 117 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7309 117 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7310 117 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7311 117 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7312 117 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7313 117 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7314 117 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7315 117 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7316 117 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7317 117 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7318 117 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7319 };
7320
7321 int32_t onScreenSaver()
7322 {
7323 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7324 int32_t oldcfgs[3];
7325 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7326 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7327 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7328
7329 large_dialog(scrsaver_dlg);
7330
7331 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7332
7333 if(ret == 8 || ret == 9)
7334 {
7335 ss_after = scrsaver_dlg[5].d1;
7336 ss_speed = scrsaver_dlg[6].d2;
7337 ss_density = scrsaver_dlg[7].d2;
7338 if(oldcfgs[0] != ss_after)
7339 zc_set_config(cfg_sect,"ss_after",ss_after);
7340 if(oldcfgs[1] != ss_speed)
7341 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7342 if(oldcfgs[2] != ss_density)
7343 zc_set_config(cfg_sect,"ss_density",ss_density);
7344 }
7345
7346 if(ret == 9)
7347 // preview Screen Saver
7348 {
7349 clear_keybuf();
7350 Matrix(ss_speed, ss_density, 30);
7351 system_pal(true);
7352 sys_mouse();
7353 }
7354
7355 return D_O_K;
7356 }
7357
7358 /***** Menus *****/
7359
7360 static MENU game_menu[] =
7361 {
7362 { (char *)"&Continue\tESC", onContinue, NULL, 0, NULL },
7363 { (char *)"", NULL, NULL, 0, NULL },
7364 { (char *)"L&oad Quest...", onCustomGame, NULL, 0, NULL },
7365 { (char *)"&End Game\tF6", onTryQuitMenu, NULL, 0, NULL },
7366 { (char *)"", NULL, NULL, 0, NULL },
7367 #ifdef __EMSCRIPTEN__
7368 { (char *)"&Reset\tF7", onReset, NULL, 0, NULL },
7369 #elif defined(ALLEGRO_MACOSX)
7370 { (char *)"&Reset\tF7", onReset, NULL, 0, NULL },
7371 { (char *)"&Quit\tF8", onExit, NULL, 0, NULL },
7372 #else
7373 { (char *)"&Reset\tF9", onReset, NULL, 0, NULL },
7374 { (char *)"&Quit\tF10", onExit, NULL, 0, NULL },
7375 #endif
7376 { NULL, NULL, NULL, 0, NULL }
7377 };
7378
7379 static MENU snapshot_format_menu[] =
7380 {
7381 { (char *)"&BMP", onSetSnapshotFormat, NULL, 0, NULL },
7382 { (char *)"&GIF", onSetSnapshotFormat, NULL, 0, NULL },
7383 { (char *)"&JPG", onSetSnapshotFormat, NULL, 0, NULL },
7384 { (char *)"&PNG", onSetSnapshotFormat, NULL, 0, NULL },
7385 { (char *)"PC&X", onSetSnapshotFormat, NULL, 0, NULL },
7386 { (char *)"&TGA", onSetSnapshotFormat, NULL, 0, NULL },
7387 { NULL, NULL, NULL, 0, NULL }
7388 };
7389
7390 static MENU controls_menu[] =
7391 {
7392 { (char *)"Key&board...", onKeyboard, NULL, 0, NULL },
7393 { (char *)"&Gamepad...", onGamepad, NULL, 0, NULL },
7394 { (char *)"&Cheat Keys...", onCheatKeys, NULL, 0, NULL },
7395 { NULL, NULL, NULL, 0, NULL }
7396 };
7397
7398 static MENU name_entry_mode_menu[] =
7399 {
7400 { (char *)"&Keyboard", onKeyboardEntry, NULL, 0, NULL },
7401 { (char *)"&Letter Grid", onLetterGridEntry, NULL, 0, NULL },
7402 { (char *)"&Extended Letter Grid", onExtLetterGridEntry, NULL, 0, NULL },
7403 { NULL, NULL, NULL, 0, NULL }
7404 };
7405
7406 static void set_controls_menu_active()
7407 {
7408
7409 }
7410
7411 static MENU window_menu[] =
7412 {
7413 { "Lock Aspect Ratio", onDragAspect, NULL, 0, NULL },
7414 { "Lock Integer Scale", onIntegerScaling, NULL, 0, NULL },
7415 { "Save Size Changes", onSaveDragResize, NULL, 0, NULL },
7416 { "Save Position Changes", onWinPosSave, NULL, 0, NULL },
7417 { "Stretch Game Area", onStretchGame, NULL, 0, NULL },
7418 { NULL, NULL, NULL, 0, NULL }
7419 };
7420 static MENU options_menu[] =
7421 {
7422 { "Name &Entry Mode", NULL, name_entry_mode_menu, 0, NULL },
7423 { "S&napshot Format", NULL, snapshot_format_menu, 0, NULL },
7424 { "&Window Settings", NULL, window_menu, 0, NULL },
7425 { "Epilepsy Flash Reduction", onEpilepsy, NULL, 0, NULL },
7426 { "Pause In Background", onPauseInBackground, NULL, 0, NULL },
7427 { NULL, NULL, NULL, 0, NULL }
7428 };
7429 static MENU settings_menu[] =
7430 {
7431 { "&Sound...", onSound, NULL, 0, NULL },
7432 { "C&ontrols", NULL, controls_menu, 0, NULL },
7433 { "", NULL, NULL, 0, NULL },
7434 { "Options", NULL, options_menu, 0, NULL },
7435 { "", NULL, NULL, 0, NULL },
7436 //
7437 { "&Cap FPS\tF1", onVsync, NULL, 0, NULL },
7438 { "Show &FPS\tF2", onShowFPS, NULL, 0, NULL },
7439 { "Click to Freeze", onClickToFreeze, NULL, 0, NULL },
7440 { "Cont. &Heart Beep", onHeartBeep, NULL, 0, NULL },
7441 { "Show Trans. &Layers", onTransLayers, NULL, 0, NULL },
7442 //
7443 { "Up+A+B To &Quit", onNESquit, NULL, 0, NULL },
7444 { "Volume &Keys", onVolKeys, NULL, 0, NULL },
7445 { "Sa&ve Indicator", onSaveIndicator, NULL, 0, NULL },
7446 { "", NULL, NULL, 0, NULL },
7447 { "Debu&g", onDebug, NULL, 0, NULL },
7448 //
7449 { NULL, NULL, NULL, 0, NULL }
7450 };
7451
7452
7453 static MENU misc_menu[] =
7454 {
7455 { (char *)"&About...", onAbout, NULL, 0, NULL },
7456 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7457 { (char *)"&Credits...", onCredits, NULL, D_DISABLED, NULL },
7458 { (char *)"&Fullscreen", onFullscreenMenu, NULL, 0, NULL },
7459 { (char *)"&Video Mode...", onVidMode, NULL, 0, NULL },
7460 { (char *)"", NULL, NULL, 0, NULL },
7461 //5
7462 { (char *)"&Quest Info...", onQuest, NULL, 0, NULL },
7463 { (char *)"Quest &MIDI Info...", onMIDICredits, NULL, 0, NULL },
7464 { (char *)"Quest &Directory...", onQstPath, NULL, 0, NULL },
7465 { (char *)"", NULL, NULL, 0, NULL },
7466 { (char *)"Take &Snapshot\tF12", onSnapshot, NULL, 0, NULL },
7467 //10
7468 { (char *)"Sc&reen Saver...", onScreenSaver, NULL, 0, NULL },
7469 { (char *)"Save ZC Configuration", OnSaveZCConfig, NULL, 0, NULL },
7470 { (char *)"Show ZASM Debugger", onConsoleZASM, NULL, 0, NULL },
7471 { (char *)"Show ZScript Debugger", onConsoleZScript, NULL, 0, NULL },
7472 { (char *)"Clear Console on Qst Load", onClrConsoleOnLoad, NULL, 0, NULL },
7473 //15
7474 { (char *)"Clear Directory Cache", OnnClearQuestDir, NULL, 0, NULL },
7475 { NULL, NULL, NULL, 0, NULL }
7476 };
7477
7478 static MENU refill_menu[] =
7479 {
7480 { (char *)"&Life", onRefillLife, NULL, 0, NULL },
7481 { (char *)"&Magic", onRefillMagic, NULL, 0, NULL },
7482 { (char *)"&Bombs", onCheatBombs, NULL, 0, NULL },
7483 { (char *)"&Rupees", onCheatRupies, NULL, 0, NULL },
7484 { (char *)"&Arrows", onCheatArrows, NULL, 0, NULL },
7485 { NULL, NULL, NULL, 0, NULL }
7486 };
7487
7488 static MENU show_menu[] =
7489 {
7490 { (char *)"Combos", onShowLayer0, NULL, 0, NULL },
7491 { (char *)"Layer 1", onShowLayer1, NULL, 0, NULL },
7492 { (char *)"Layer 2", onShowLayer2, NULL, 0, NULL },
7493 { (char *)"Layer 3", onShowLayer3, NULL, 0, NULL },
7494 { (char *)"Layer 4", onShowLayer4, NULL, 0, NULL },
7495 { (char *)"Layer 5", onShowLayer5, NULL, 0, NULL },
7496 { (char *)"Layer 6", onShowLayer6, NULL, 0, NULL },
7497 { (char *)"Overhead Combos", onShowLayerO, NULL, 0, NULL },
7498 { (char *)"Push Blocks", onShowLayerP, NULL, 0, NULL },
7499 { (char *)"Freeform Combos", onShowLayerF, NULL, 0, NULL },
7500 { (char *)"Sprites", onShowLayerS, NULL, 0, NULL },
7501 { (char *)"", NULL, NULL, 0, NULL },
7502 { (char *)"Current FFC Scripts", onShowFFScripts, NULL, 0, NULL },
7503 { (char *)"", NULL, NULL, 0, NULL },
7504 { (char *)"Walkability", onShowLayerW, NULL, 0, NULL },
7505 { (char *)"Hitboxes", onShowHitboxes, NULL, 0, NULL },
7506 { (char *)"Effects", onShowLayerE, NULL, 0, NULL },
7507 { (char *)"Info Opacity", onShowInfoOpacity, NULL, 0, NULL },
7508 { NULL, NULL, NULL, 0, NULL }
7509 };
7510
7511 static MENU cheat_menu[] =
7512 {
7513 { (char *)"Set &Cheat", onCheat, NULL, 0, NULL },
7514 { (char *)"", NULL, NULL, 0, NULL },
7515 { (char *)"Re&fill", NULL, refill_menu, 0, NULL },
7516 { (char *)"", NULL, NULL, 0, NULL },
7517 { (char *)"&Invincible", onClock, NULL, 0, NULL },
7518 { (char *)"Ma&x Bombs...", onMaxBombs, NULL, 0, NULL },
7519 { (char *)"&Heart Containers...", onHeartC, NULL, 0, NULL },
7520 { (char *)"&Magic Containers...", onMagicC, NULL, 0, NULL },
7521 { (char *)"", NULL, NULL, 0, NULL },
7522 { (char *)"&Player Data...", onCheatConsole, NULL, 0, NULL },
7523 { (char *)"", NULL, NULL, 0, NULL },
7524 { (char *)"Walk Through &Walls", onNoWalls, NULL, 0, NULL },
7525 { (char *)"Player Ignores Side&view", onIgnoreSideview, NULL, 0, NULL },
7526 { (char *)"&Quick Movement", onGoFast, NULL, 0, NULL },
7527 { (char *)"&Kill All Enemies", onKillCheat, NULL, 0, NULL },
7528 { (char *)"Trigger &Secrets", onSecretsCheat, NULL, 0, NULL },
7529 { (char *)"Trigger Secrets Perm", onSecretsCheatPerm, NULL, 0, NULL },
7530 { (char *)"Show/Hide Layer", NULL, show_menu, 0, NULL },
7531 { (char *)"Toggle &Light", onLightSwitch, NULL, 0, NULL },
7532 { (char *)"&Goto Location...", onGoTo, NULL, 0, NULL },
7533 { NULL, NULL, NULL, 0, NULL }
7534 };
7535
7536 #if DEVLEVEL > 0
7537 int32_t devLogging();
7538 int32_t devDebug();
7539 int32_t devTimestmp();
7540 #if DEVLEVEL > 1
7541 int32_t setCheat();
7542 #endif //DEVLEVEL > 1
7543 enum
7544 {
7545 dv_log,
7546 // dv_dbg,
7547 dv_tmpstmp,
7548 #if DEVLEVEL > 1
7549 dv_nil,
7550 dv_setcheat,
7551 #endif //DEVLEVEL > 1
7552 dv_max
7553 };
7554 static MENU dev_menu[] =
7555 {
7556 { (char *)"&Force Error Log", devLogging, NULL, 0, NULL },
7557 // { (char *)"&Extra Debug Log", devDebug, NULL, 0, NULL },
7558 { (char *)"&Timestamp Log", devTimestmp, NULL, 0, NULL },
7559 #if DEVLEVEL > 1
7560 { (char *)"", NULL, NULL, 0, NULL },
7561 { (char *)"Set &Cheat", setCheat, NULL, 0, NULL },
7562 #endif //DEVLEVEL > 1
7563 { NULL, NULL, NULL, 0, NULL }
7564 };
7565 int32_t devLogging()
7566 {
7567 dev_logging = !dev_logging;
7568 dev_menu[dv_log].flags = dev_logging ? D_SELECTED : 0;
7569 return D_O_K;
7570 }
7571 // int32_t devDebug()
7572 // {
7573 // dev_debug = !dev_debug;
7574 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7575 // return D_O_K;
7576 // }
7577 int32_t devTimestmp()
7578 {
7579 dev_timestmp = !dev_timestmp;
7580 dev_menu[dv_tmpstmp].flags = dev_timestmp ? D_SELECTED : 0;
7581 return D_O_K;
7582 }
7583 #if DEVLEVEL > 1
7584 int32_t setCheat()
7585 {
7586 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7587 return D_O_K;
7588 }
7589 #endif //DEVLEVEL > 1
7590 #endif //DEVLEVEL > 0
7591
7592 MENU the_player_menu[] =
7593 {
7594 { (char *)"&Game", NULL, game_menu, 0, NULL },
7595 { (char *)"&Settings", NULL, settings_menu, 0, NULL },
7596 { (char *)"&Cheat", NULL, cheat_menu, 0, NULL },
7597 { (char *)"Replay", NULL, replay_menu, 0, NULL },
7598 { (char *)"&ZC", NULL, misc_menu, 0, NULL },
7599 #if DEVLEVEL > 0
7600 { (char *)"&Dev", NULL, dev_menu, 0, NULL },
7601 #endif
7602 { NULL, NULL, NULL, 0, NULL }
7603 };
7604 int32_t onPauseInBackground()
7605 {
7606 if(jwin_alert3(
7607 "Toggle Pause In Background",
7608 "This action will change whether ZC Player pauses when the window loses focus.",
7609 "",
7610 "Proceed?",
7611 "&Yes",
7612 "&No",
7613 NULL,
7614 'y',
7615 'n',
7616 0,
7617 get_zc_font(font_lfont)) == 1)
7618 {
7619 pause_in_background = pause_in_background ? 0 : 1;
7620 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7621 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7622 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7623 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7624 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7625 }
7626 options_menu[4].flags =(pause_in_background)?D_SELECTED:0;
7627 return D_O_K;
7628 }
7629
7630 int32_t onKeyboardEntry()
7631 {
7632 NameEntryMode=0;
7633 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7634 return D_O_K;
7635 }
7636
7637 int32_t onLetterGridEntry()
7638 {
7639 NameEntryMode=1;
7640 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7641 return D_O_K;
7642 }
7643
7644 int32_t onExtLetterGridEntry()
7645 {
7646 NameEntryMode=2;
7647 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7648 return D_O_K;
7649 }
7650
7651 static BITMAP* oldscreen;
7652 int32_t onFullscreenMenu()
7653 {
7654 // super hacks
7655 screen = oldscreen;
7656 if (onFullscreen() == D_REDRAW)
7657 {
7658 oldscreen = screen;
7659 }
7660 screen = menu_bmp;
7661 misc_menu[2].flags =(isFullScreen()==1)?D_SELECTED:0;
7662 return D_O_K;
7663 }
7664
7665 117 void fix_menu()
7666 {
7667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
117 if(!debug_enabled)
7668 117 settings_menu[13].text = NULL;
7669 117 }
7670
7671 static DIALOG system_dlg[] =
7672 {
7673 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
7674 { jwin_menu_proc, 0, 0, 0, 0, 0, 0, 0, D_USER, 0, 0, (void *) the_player_menu, NULL, NULL },
7675 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onVsync, NULL, NULL },
7676 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F2, 0, (void *) onShowFPS, NULL, NULL },
7677 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F6, 0, (void *) onTryQuitMenu, NULL, NULL },
7678 #ifndef ALLEGRO_MACOSX
7679 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F9, 0, (void *) onReset, NULL, NULL },
7680 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F10, 0, (void *) onExit, NULL, NULL },
7681 #else
7682 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F7, 0, (void *) onReset, NULL, NULL },
7683 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F8, 0, (void *) onExit, NULL, NULL },
7684 #endif
7685 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F12, 0, (void *) onSnapshot, NULL, NULL },
7686 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_TAB, 0, (void *) onDebug, NULL, NULL },
7687 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7688 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7689 };
7690
7691 void reset_snapshot_format_menu()
7692 {
7693 for(int32_t i=0; i<ssfmtMAX; ++i)
7694 {
7695 snapshot_format_menu[i].flags=0;
7696 }
7697 }
7698
7699 int32_t onSetSnapshotFormat()
7700 {
7701 switch(active_menu->text[1])
7702 {
7703 case 'B': //"&BMP"
7704 SnapshotFormat=0;
7705 break;
7706
7707 case 'G': //"&GIF"
7708 SnapshotFormat=1;
7709 break;
7710
7711 case 'J': //"&JPG"
7712 SnapshotFormat=2;
7713 break;
7714
7715 case 'P': //"&PNG"
7716 SnapshotFormat=3;
7717 break;
7718
7719 case 'C': //"PC&X"
7720 SnapshotFormat=4;
7721 break;
7722
7723 case 'T': //"&TGA"
7724 SnapshotFormat=5;
7725 break;
7726
7727 case 'L': //"&LBM"
7728 SnapshotFormat=6;
7729 break;
7730 }
7731 zc_set_config("zeldadx", "snapshot_format", SnapshotFormat);
7732
7733 snapshot_format_menu[SnapshotFormat].flags=D_SELECTED;
7734 return D_O_K;
7735 }
7736
7737
7738 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7739 {
7740 PALETTE tmp;
7741
7742 for(int32_t i=0; i<256; i++)
7743 {
7744 tmp[i].r=r;
7745 tmp[i].g=g;
7746 tmp[i].b=b;
7747 }
7748
7749 fade_interpolate(src,tmp,dest,pos,from,to);
7750 }
7751
7752 14 void system_pal(bool force)
7753 {
7754
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(is_sys_pal && !force) return;
7755 14 is_sys_pal = true;
7756 14 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7757 14 hw_palette = &syspal;
7758 14 update_hw_pal = true;
7759 14 }
7760
7761 static uint32_t entered_sys_pal = 0;
7762 14 void enter_sys_pal()
7763 {
7764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(is_sys_pal)
7765 {
7766 if(entered_sys_pal)
7767 ++entered_sys_pal;
7768 return;
7769 }
7770 14 sys_mouse();
7771 14 system_pal(true);
7772 14 ++entered_sys_pal;
7773 14 }
7774 14 void exit_sys_pal()
7775 {
7776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(entered_sys_pal)
7777 {
7778
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!--entered_sys_pal)
7779 {
7780 14 game_pal();
7781 14 game_mouse();
7782 14 }
7783 14 }
7784 14 }
7785
7786 void switch_out_callback()
7787 {
7788 if (pause_in_background && !MenuOpen)
7789 {
7790 System();
7791 }
7792 }
7793
7794 void switch_in_callback()
7795 {
7796 }
7797
7798 424 void game_pal()
7799 {
7800 424 is_sys_pal = false;
7801 424 entered_sys_pal = 0;
7802 424 hw_palette = &RAMpal;
7803 424 update_hw_pal = true;
7804 424 }
7805
7806 static char bar_str[] = "";
7807
7808 14 void music_pause()
7809 {
7810 //al_pause_duh(tmplayer);
7811 14 zcmusic_pause(zcmusic, ZCM_PAUSE);
7812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(zcmixer->oldtrack)
7813 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7814 14 zc_midi_pause();
7815 14 }
7816
7817 void music_resume()
7818 {
7819 //al_resume_duh(tmplayer);
7820 zcmusic_pause(zcmusic, ZCM_RESUME);
7821 if (zcmixer->oldtrack)
7822 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7823 zc_midi_resume();
7824 }
7825
7826 3361 void music_stop()
7827 {
7828 //al_stop_duh(tmplayer);
7829 //unload_duh(tmusic);
7830 //tmusic=NULL;
7831 //tmplayer=NULL;
7832 3361 zcmusic_stop(zcmusic);
7833 3361 zcmusic_unload_file(zcmusic);
7834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 if (zcmixer->oldtrack)
7835 {
7836 zcmusic_stop(zcmixer->oldtrack);
7837 zcmusic_unload_file(zcmixer->oldtrack);
7838 }
7839 3361 zcmixer->newtrack = NULL;
7840 3361 zc_stop_midi();
7841 3361 currmidi=-1;
7842 3361 }
7843
7844 void System()
7845 {
7846 mouse_down=gui_mouse_b();
7847 music_pause();
7848 pause_all_sfx();
7849 MenuOpen = true;
7850 enter_sys_pal();
7851 // FONT *oldfont=font;
7852 // font=tfont;
7853
7854 misc_menu[2].flags =(isFullScreen()==1)?D_SELECTED:0;
7855 misc_menu[3].flags =(isFullScreen()==1)?D_DISABLED:0;
7856
7857 game_menu[2].flags = getsaveslot() > -1 ? 0 : D_DISABLED;
7858 #if DEVLEVEL > 1
7859 dev_menu[dv_setcheat].flags = Playing ? 0 : D_DISABLED;
7860 #endif
7861 game_menu[3].flags =
7862 misc_menu[5].flags = Playing ? 0 : D_DISABLED;
7863 misc_menu[7].flags = !Playing ? 0 : D_DISABLED;
7864 clear_keybuf();
7865
7866 DIALOG_PLAYER *p;
7867
7868 clear_bitmap(menu_bmp);
7869 oldscreen = screen;
7870 screen = menu_bmp;
7871
7872 p = init_dialog(system_dlg,-1);
7873
7874 // drop the menu on startup if menu button pressed
7875 if(joybtn(Mbtn)||zc_getrawkey(KEY_ESC))
7876 simulate_keypress(KEY_G << 8);
7877
7878 do
7879 {
7880 if(handle_close_btn_quit())
7881 break;
7882
7883 rest(17);
7884
7885 if(mouse_down && !gui_mouse_b())
7886 mouse_down=0;
7887
7888 settings_menu[1].flags = replay_is_replaying() ? D_DISABLED : 0;
7889 settings_menu[5].flags = Throttlefps?D_SELECTED:0;
7890 settings_menu[6].flags = ShowFPS?D_SELECTED:0;
7891 settings_menu[7].flags = ClickToFreeze?D_SELECTED:0;
7892 settings_menu[9].flags = TransLayers?D_SELECTED:0;
7893 settings_menu[10].flags = NESquit?D_SELECTED:0;
7894 settings_menu[11].flags = volkeys?D_SELECTED:0;
7895
7896 window_menu[0].flags = DragAspect?D_SELECTED:0;
7897 window_menu[1].flags = scaleForceInteger?D_SELECTED:0;
7898 window_menu[2].flags = SaveDragResize?D_SELECTED:0;
7899 window_menu[3].flags = SaveWinPos?D_SELECTED:0;
7900 window_menu[4].flags = stretchGame?D_SELECTED:0;
7901
7902 options_menu[3].flags = (epilepsyFlashReduction) ? D_SELECTED : 0;
7903 options_menu[4].flags = (pause_in_background)?D_SELECTED:0;
7904
7905 name_entry_mode_menu[0].flags = (NameEntryMode==0)?D_SELECTED:0;
7906 name_entry_mode_menu[1].flags = (NameEntryMode==1)?D_SELECTED:0;
7907 name_entry_mode_menu[2].flags = (NameEntryMode==2)?D_SELECTED:0;
7908
7909 misc_menu[12].flags =(zasm_debugger)?D_SELECTED:0;
7910 misc_menu[13].flags =(zscript_debugger)?D_SELECTED:0;
7911 misc_menu[14].flags =(clearConsoleOnLoad)?D_SELECTED:0;
7912
7913 bool nocheat = (replay_is_replaying() || !Playing
7914 || (!zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7915 the_player_menu[2].flags = nocheat ? D_DISABLED : 0;
7916 cheat_menu[0].flags = 0;
7917 refill_menu[4].flags = get_qr(qr_TRUEARROWS) ? 0 : D_DISABLED;
7918 cheat_menu[1].text = (cheat >= 1) || get_debug() ? bar_str : NULL;
7919 cheat_menu[3].text = (cheat >= 2) || get_debug() ? bar_str : NULL;
7920 cheat_menu[8].text = (cheat >= 3) || get_debug() ? bar_str : NULL;
7921 cheat_menu[10].text = (cheat >= 4) || get_debug() ? bar_str : NULL;
7922 cheat_menu[4].flags = getClock() ? D_SELECTED : 0;
7923 cheat_menu[11].flags = toogam ? D_SELECTED : 0;
7924 cheat_menu[12].flags = ignoreSideview ? D_SELECTED : 0;
7925 cheat_menu[13].flags = gofast ? D_SELECTED : 0;
7926
7927 show_menu[0].flags = show_layer_0 ? D_SELECTED : 0;
7928 show_menu[1].flags = show_layer_1 ? D_SELECTED : 0;
7929 show_menu[2].flags = show_layer_2 ? D_SELECTED : 0;
7930 show_menu[3].flags = show_layer_3 ? D_SELECTED : 0;
7931 show_menu[4].flags = show_layer_4 ? D_SELECTED : 0;
7932 show_menu[5].flags = show_layer_5 ? D_SELECTED : 0;
7933 show_menu[6].flags = show_layer_6 ? D_SELECTED : 0;
7934 show_menu[7].flags = show_layer_over ? D_SELECTED : 0;
7935 show_menu[8].flags = show_layer_push ? D_SELECTED : 0;
7936 show_menu[9].flags = show_sprites ? D_SELECTED : 0;
7937 show_menu[10].flags = show_ffcs ? D_SELECTED : 0;
7938 show_menu[12].flags = show_walkflags ? D_SELECTED : 0;
7939 show_menu[13].flags = show_ff_scripts ? D_SELECTED : 0;
7940 show_menu[14].flags = show_hitboxes ? D_SELECTED : 0;
7941 show_menu[15].flags = show_effectflags ? D_SELECTED : 0;
7942
7943 settings_menu[8].flags = heart_beep ? D_SELECTED : 0;
7944 settings_menu[12].flags = use_save_indicator ? D_SELECTED : 0;
7945
7946 replay_menu[0].text = zc_get_config("zeldadx", "replay_new_saves", false) ?
7947 (char *)"Disable recording new saves" :
7948 (char *)"Enable recording new saves";
7949 replay_menu[1].flags = replay_is_active() ? 0 : D_DISABLED;
7950 replay_menu[1].text = replay_get_mode() == ReplayMode::Record ?
7951 (char *)"Stop recording" :
7952 (char *)"Stop replaying";
7953 replay_menu[5].flags = replay_get_mode() == ReplayMode::Record ? 0 : D_DISABLED;
7954 replay_menu[6].text = replay_is_snapshot_all_frames() ?
7955 (char *)"Disable snapshot all frames" :
7956 (char *)"Enable snapshot all frames";
7957
7958 reset_snapshot_format_menu();
7959 snapshot_format_menu[SnapshotFormat].flags = D_SELECTED;
7960
7961 if(debug_enabled)
7962 {
7963 settings_menu[14].flags = get_debug() ? D_SELECTED : 0;
7964 }
7965
7966 if(gui_mouse_b() && !mouse_down)
7967 break;
7968
7969 // press menu to drop the menu
7970 if(rMbtn())
7971 simulate_keypress(KEY_G << 8);
7972
7973 if(input_idle(true) > after_time())
7974 // run Screeen Saver
7975 {
7976 // Screen saver enabled for now.
7977 clear_keybuf();
7978 Matrix(ss_speed, ss_density, 0);
7979 system_pal(true);
7980 sys_mouse();
7981 broadcast_dialog_message(MSG_DRAW, 0);
7982 }
7983
7984 update_hw_screen();
7985 }
7986 while(update_dialog(p));
7987
7988 screen = oldscreen;
7989
7990 // font=oldfont;
7991 mouse_down=gui_mouse_b();
7992 shutdown_dialog(p);
7993 MenuOpen = false;
7994 if(Quit)
7995 {
7996 kill_sfx();
7997 music_stop();
7998 update_hw_screen();
7999 }
8000 else
8001 {
8002 music_resume();
8003 resume_all_sfx();
8004
8005 if(rc)
8006 ringcolor(false);
8007 }
8008 exit_sys_pal();
8009
8010 eat_buttons();
8011
8012 rc=false;
8013 clear_keybuf();
8014
8015 zc_init_apply_cheat_delta();
8016 }
8017
8018 117 void fix_dialogs()
8019 {
8020 117 jwin_center_dialog(about_dlg);
8021 117 jwin_center_dialog(gamepad_dlg);
8022 117 jwin_center_dialog(credits_dlg);
8023 117 jwin_center_dialog(gamemode_dlg);
8024 117 jwin_center_dialog(getnum_dlg);
8025 117 jwin_center_dialog(goto_dlg);
8026 117 jwin_center_dialog(keyboard_control_dlg);
8027 117 jwin_center_dialog(midi_dlg);
8028 117 jwin_center_dialog(quest_dlg);
8029 117 jwin_center_dialog(scrsaver_dlg);
8030 117 jwin_center_dialog(sound_dlg);
8031 117 jwin_center_dialog(triforce_dlg);
8032
8033 // digi_dp[1] += scrx;
8034 // digi_dp[2] += scry;
8035 // midi_dp[1] += scrx;
8036 // midi_dp[2] += scry;
8037 // pan_dp[1] += scrx;
8038 // pan_dp[2] += scry;
8039 // emus_dp[1] += scrx;
8040 // emus_dp[2] += scry;
8041 // buf_dp[1] += scrx;
8042 // buf_dp[2] += scry;
8043 // sfx_dp[1] += scrx;
8044 // sfx_dp[2] += scry;
8045 117 }
8046
8047 /*****************************/
8048 /**** Custom Sound System ****/
8049 /*****************************/
8050
8051 117 INLINE int32_t mixvol(int32_t v1,int32_t v2)
8052 {
8053
2/4
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
117 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
8054 }
8055
8056 // Run an NSF, or a MIDI if the NSF is missing somehow.
8057 149 bool try_zcmusic(const char *filename, int32_t track, int32_t midi, int32_t fadeoutframes)
8058 {
8059 149 ZCMUSIC *newzcmusic = zcmusic_load_for_quest(filename, qstpath);
8060
8061 // Found it
8062
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if(newzcmusic!=NULL)
8063 {
8064 newzcmusic->fadevolume = 10000;
8065 newzcmusic->fadeoutframes = fadeoutframes;
8066
8067 zcmixer->newtrack = newzcmusic;
8068
8069 zcmusic_stop(zcmusic);
8070 zcmusic_unload_file(zcmusic);
8071 zc_stop_midi();
8072
8073 zcmusic=newzcmusic;
8074 int32_t temp_volume = emusic_volume;
8075 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8076 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
8077 temp_volume = (temp_volume * zcmusic->fadevolume) / 10000;
8078 zcmusic_play(zcmusic, temp_volume);
8079
8080 if(track>0)
8081 zcmusic_change_track(zcmusic,track);
8082
8083 return true;
8084 }
8085
8086 // Not found, play MIDI - unless this was called by a script (yay, magic numbers)
8087
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 70 times.
149 else if(midi>-1000)
8088 70 jukebox(midi);
8089
8090 149 return false;
8091 149 }
8092
8093 bool try_zcmusic_ex(char *filename, int32_t track, int32_t midi)
8094 {
8095 ZCMUSIC *newzcmusic = zcmusic_load_for_quest(filename, qstpath);
8096 // Found it
8097 if(newzcmusic!=NULL)
8098 {
8099 zcmusic_stop(zcmusic);
8100 zcmusic_unload_file(zcmusic);
8101 zc_stop_midi();
8102
8103 zcmusic=newzcmusic;
8104 zcmusic_play(zcmusic, emusic_volume);
8105
8106 if(track>0)
8107 zcmusic_change_track(zcmusic,track);
8108
8109 return true;
8110 }
8111
8112 // Not found, play MIDI - unless this was called by a script (yay, magic numbers)
8113 else if(midi>-1000)
8114 jukebox(midi);
8115
8116 return false;
8117 }
8118
8119 int32_t get_zcmusicpos()
8120 {
8121 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
8122 return debugtracething;
8123 return 0;
8124 }
8125
8126 void set_zcmusicpos(int32_t position)
8127 {
8128 zcmusic_set_curpos(zcmusic, position);
8129 }
8130
8131 void set_zcmusicspeed(int32_t speed)
8132 {
8133 zcmusic_set_speed(zcmusic, speed);
8134 }
8135
8136 int32_t get_zcmusiclen()
8137 {
8138 return zcmusic_get_length(zcmusic);
8139 }
8140
8141 void set_zcmusicloop(double start, double end)
8142 {
8143 zcmusic_set_loop(zcmusic, start, end);
8144 }
8145
8146 63941 void jukebox(int32_t index,int32_t loop)
8147 {
8148
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if (is_headless())
8149 63941 return;
8150
8151 music_stop();
8152
8153 if(index<0) index=MAXMIDIS-1;
8154
8155 if(index>=MAXMIDIS) index=0;
8156
8157 music_stop();
8158
8159 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8160 // stuck notes when a song stops. This fixes it.
8161 if(strcmp(midi_driver->name, "DIGMID")==0)
8162 zc_set_volume(0, 0);
8163
8164 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8165 zc_play_midi((MIDI*)tunes[index].data,loop);
8166
8167 if(tunes[index].start>0)
8168 zc_midi_seek(tunes[index].start);
8169
8170 midi_loop_start = tunes[index].loop_start;
8171 midi_loop_end = tunes[index].loop_end;
8172
8173 currmidi=index;
8174 master_volume(digi_volume, midi_volume);
8175 //midi_paused=false;
8176 63941 }
8177
8178 63941 void jukebox(int32_t index)
8179 {
8180
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if(index<0) index=MAXMIDIS-1;
8181
8182
1/2
✓ Branch 0 taken 63941 times.
✗ Branch 1 not taken.
63941 if(index>=MAXMIDIS) index=0;
8183
8184 // do nothing if it's already playing
8185
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 63941 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
63941 if(index==currmidi && midi_pos>=0)
8186 {
8187 return;
8188 }
8189
8190 63941 jukebox(index,tunes[index].loop);
8191 63941 }
8192
8193 16 void play_DmapMusic()
8194 {
8195
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (is_headless())
8196 16 return;
8197
8198 static char tfile[2048];
8199 static int32_t ttrack=0;
8200 bool domidi=false;
8201
8202 int32_t fadeoutframes = 0;
8203 if (zcmusic != NULL)
8204 fadeoutframes = zcmusic->fadeoutframes;
8205
8206 if(DMaps[currdmap].tmusic[0]!=0)
8207 {
8208 if(zcmusic==NULL ||
8209 strcmp(zcmusic->filename,DMaps[currdmap].tmusic)!=0 ||
8210 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[currdmap].tmusictrack))
8211 {
8212 if (DMaps[currdmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8213 {
8214 if (FFCore.play_enh_music_crossfade(DMaps[currdmap].tmusic, DMaps[currdmap].tmusictrack, DMaps[currdmap].tmusic_xfade_in, fadeoutframes))
8215 {
8216 if (zcmusic != NULL)
8217 {
8218 zcmusic->fadeoutframes = DMaps[currdmap].tmusic_xfade_out;
8219 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8220 }
8221 }
8222 }
8223 else
8224 {
8225 if (zcmusic != NULL)
8226 {
8227 zcmusic_stop(zcmusic);
8228 zcmusic_unload_file(zcmusic);
8229 zcmusic = NULL;
8230 zcmixer->newtrack = NULL;
8231 }
8232
8233 zcmusic = zcmusic_load_for_quest(DMaps[currdmap].tmusic, qstpath);
8234 zcmixer->newtrack = zcmusic;
8235
8236 if (zcmusic != NULL)
8237 {
8238 zc_stop_midi();
8239 strcpy(tfile, DMaps[currdmap].tmusic);
8240 zcmusic_play(zcmusic, emusic_volume);
8241 int32_t temptracks = 0;
8242 temptracks = zcmusic_get_tracks(zcmusic);
8243 temptracks = (temptracks < 2) ? 1 : temptracks;
8244 ttrack = vbound(DMaps[currdmap].tmusictrack, 0, temptracks - 1);
8245 zcmusic_change_track(zcmusic, ttrack);
8246 zcmusic_set_loop(zcmusic, double(DMaps[currdmap].tmusic_loop_start / 10000.0), double(DMaps[currdmap].tmusic_loop_end / 10000.0));
8247 }
8248 else
8249 {
8250 tfile[0] = 0;
8251 domidi = true;
8252 }
8253 }
8254 }
8255 }
8256 else
8257 {
8258 if (DMaps[currdmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[currdmap].tmusic) != 0)
8259 {
8260 FFCore.play_enh_music_crossfade(NULL, DMaps[currdmap].tmusictrack, DMaps[currdmap].tmusic_xfade_in, fadeoutframes);
8261 }
8262 else
8263 {
8264 domidi = true;
8265 }
8266 }
8267
8268 if(domidi)
8269 {
8270 int32_t m=DMaps[currdmap].midi;
8271
8272 switch(m)
8273 {
8274 case 1:
8275 jukebox(ZC_MIDI_OVERWORLD);
8276 break;
8277
8278 case 2:
8279 jukebox(ZC_MIDI_DUNGEON);
8280 break;
8281
8282 case 3:
8283 jukebox(ZC_MIDI_LEVEL9);
8284 break;
8285
8286 default:
8287 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8288 jukebox(m+MIDIOFFSET_DMAP);
8289 else
8290 music_stop();
8291 }
8292 }
8293 16 }
8294
8295 15755 void playLevelMusic()
8296 {
8297
1/2
✓ Branch 0 taken 15755 times.
✗ Branch 1 not taken.
15755 if (is_headless())
8298 15755 return;
8299
8300 int32_t m=tmpscr->screen_midi;
8301
8302 switch(m)
8303 {
8304 case -2:
8305 music_stop();
8306 break;
8307
8308 case -1:
8309 play_DmapMusic();
8310 break;
8311
8312 case 1:
8313 jukebox(ZC_MIDI_OVERWORLD);
8314 break;
8315
8316 case 2:
8317 jukebox(ZC_MIDI_DUNGEON);
8318 break;
8319
8320 case 3:
8321 jukebox(ZC_MIDI_LEVEL9);
8322 break;
8323
8324 default:
8325 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8326 jukebox(m+MIDIOFFSET_MAPSCR);
8327 else
8328 music_stop();
8329 }
8330 15755 }
8331
8332 117 void master_volume(int32_t dv,int32_t mv)
8333 {
8334
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 117 times.
✗ Branch 7 not taken.
117 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8335
8336
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 117 times.
✗ Branch 7 not taken.
117 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8337
8338
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
✓ Branch 2 taken 117 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 117 times.
117 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8339 117 int32_t temp_vol = midi_volume;
8340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
117 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8341 117 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8342 117 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8343 117 }
8344
8345 /*****************/
8346 /***** SFX *****/
8347 /*****************/
8348
8349 // array of voices, one for each sfx sample in the data file
8350 // 0+ = voice #
8351 // -1 = voice not allocated
8352 117 void Z_init_sound()
8353 {
8354
2/2
✓ Branch 0 taken 29952 times.
✓ Branch 1 taken 117 times.
30069 for(int32_t i=0; i<WAV_COUNT; i++)
8355 29952 sfx_voice[i]=-1;
8356
8357 117 const char* midis[ZC_MIDI_COUNT] = {
8358 "assets/dungeon.mid",
8359 "assets/ending.mid",
8360 "assets/gameover.mid",
8361 "assets/level9.mid",
8362 "assets/overworld.mid",
8363 "assets/title.mid",
8364 "assets/triforce.mid",
8365 };
8366
2/2
✓ Branch 0 taken 819 times.
✓ Branch 1 taken 117 times.
936 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8367 {
8368 819 tunes[i].data = load_midi(midis[i]);
8369
1/2
✓ Branch 0 taken 819 times.
✗ Branch 1 not taken.
819 if (!tunes[i].data)
8370 Z_error_fatal("Missing required file %s\n", midis[i]);
8371 819 }
8372
8373
2/2
✓ Branch 0 taken 29484 times.
✓ Branch 1 taken 117 times.
29601 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8374 29484 tunes[ZC_MIDI_COUNT+j].data=NULL;
8375
8376 117 master_volume(digi_volume,midi_volume);
8377 117 }
8378
8379 // returns number of voices currently allocated
8380 int32_t sfx_count()
8381 {
8382 int32_t c=0;
8383
8384 for(int32_t i=0; i<WAV_COUNT; i++)
8385 if(sfx_voice[i]!=-1)
8386 ++c;
8387
8388 return c;
8389 }
8390
8391 // clean up finished samples
8392 9218467 void sfx_cleanup()
8393 {
8394
2/2
✓ Branch 0 taken 2359927552 times.
✓ Branch 1 taken 9218467 times.
2369146019 for(int32_t i=0; i<WAV_COUNT; i++)
8395
3/4
✓ Branch 0 taken 619766 times.
✓ Branch 1 taken 2359307786 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 619766 times.
2360547318 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8396 {
8397 619766 deallocate_voice(sfx_voice[i]);
8398 619766 sfx_voice[i]=-1;
8399 619766 }
8400 9218467 }
8401
8402 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8403 // if a voice is already allocated (and/or playing), then it just returns true
8404 // Returns true: voice is allocated
8405 // false: unsuccessful
8406 964184 bool sfx_init(int32_t index)
8407 {
8408 // check index
8409
3/4
✓ Branch 0 taken 721795 times.
✓ Branch 1 taken 242389 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 721795 times.
964184 if(index<=0 || index>=WAV_COUNT)
8410 242389 return false;
8411
8412
2/2
✓ Branch 0 taken 102011 times.
✓ Branch 1 taken 619784 times.
721795 if(sfx_voice[index]==-1)
8413 {
8414
2/2
✓ Branch 0 taken 209876 times.
✓ Branch 1 taken 409908 times.
619784 if(sfxdat)
8415 {
8416
1/2
✓ Branch 0 taken 209876 times.
✗ Branch 1 not taken.
209876 if(index<Z35)
8417 {
8418 209876 sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[index].dat);
8419 209876 }
8420 else
8421 {
8422 sfx_voice[index]=allocate_voice((SAMPLE*)sfxdata[Z35].dat);
8423 }
8424 209876 }
8425 else
8426 {
8427 409908 sfx_voice[index]=allocate_voice(&customsfxdata[index]);
8428 }
8429
8430 619784 int32_t temp_volume = sfx_volume;
8431
2/4
✓ Branch 0 taken 619784 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 619784 times.
✗ Branch 3 not taken.
619784 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8432 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8433 619784 voice_set_volume(sfx_voice[index], temp_volume);
8434 619784 }
8435
8436 721795 return sfx_voice[index] != -1;
8437 964184 }
8438
8439 int32_t sfx_get_default_freq(int32_t index)
8440 {
8441 if (sfxdat)
8442 {
8443 if (index < Z35)
8444 {
8445 return ((SAMPLE*)sfxdata[index].dat)->freq;
8446 }
8447 else
8448 {
8449 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8450 }
8451 }
8452 else
8453 {
8454 return customsfxdata[index].freq;
8455 }
8456 }
8457
8458 int32_t sfx_get_length(int32_t index)
8459 {
8460 if (sfxdat)
8461 {
8462 if (index < Z35)
8463 {
8464 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8465 }
8466 else
8467 {
8468 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8469 }
8470 }
8471 else
8472 {
8473 return int32_t(customsfxdata[index].len);
8474 }
8475 }
8476
8477 // plays an sfx sample
8478 964184 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8479 {
8480
2/2
✓ Branch 0 taken 721795 times.
✓ Branch 1 taken 242389 times.
964184 if(!sfx_init(index))
8481 242389 return;
8482
1/2
✓ Branch 0 taken 721795 times.
✗ Branch 1 not taken.
721795 if (!is_headless())
8483 {
8484 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8485 voice_set_pan(sfx_voice[index], pan);
8486
8487 // Only used by ZScript currently
8488 if (freq <= -1)
8489 {
8490 freq = sfx_get_default_freq(index);
8491 }
8492 voice_set_frequency(sfx_voice[index], freq);
8493
8494 // Only used by ZScript currently
8495 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8496 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8497 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8498 voice_set_volume(sfx_voice[index], temp_volume);
8499
8500 int32_t pos = voice_get_position(sfx_voice[index]);
8501
8502 if (restart) voice_set_position(sfx_voice[index], 0);
8503
8504 if (pos <= 0)
8505 voice_start(sfx_voice[index]);
8506 }
8507
8508
3/4
✓ Branch 0 taken 398004 times.
✓ Branch 1 taken 323791 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 398004 times.
721795 if (restart && replay_is_debug())
8509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 398004 times.
398004 replay_step_comment(fmt::format("sfx {}", sfx_string[index]));
8510 964184 }
8511
8512 // true if sfx is allocated
8513 68052 bool sfx_allocated(int32_t index)
8514 {
8515
3/4
✓ Branch 0 taken 9923 times.
✓ Branch 1 taken 58129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9923 times.
68052 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8516 }
8517
8518 // start it (in loop mode) if it's not already playing,
8519 // otherwise adjust it to play in loop mode -DD
8520 55174 void cont_sfx(int32_t index)
8521 {
8522
1/2
✓ Branch 0 taken 55174 times.
✗ Branch 1 not taken.
55174 if (is_headless())
8523 55174 return;
8524
8525 if(!sfx_init(index))
8526 {
8527 return;
8528 }
8529
8530 if(voice_get_position(sfx_voice[index])<=0)
8531 {
8532 voice_set_position(sfx_voice[index],0);
8533 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8534 voice_start(sfx_voice[index]);
8535 }
8536 else
8537 {
8538 adjust_sfx(index, 128, true);
8539 }
8540 55174 }
8541
8542 // adjust parameters while playing
8543 4075 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8544 {
8545
4/6
✓ Branch 0 taken 2315 times.
✓ Branch 1 taken 1760 times.
✓ Branch 2 taken 2315 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2315 times.
4075 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8546 4075 return;
8547
8548 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8549 voice_set_pan(sfx_voice[index],pan);
8550 4075 }
8551
8552 // pauses a voice
8553 1725 void pause_sfx(int32_t index)
8554 {
8555
3/6
✓ Branch 0 taken 1725 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1725 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1725 times.
1725 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8556 voice_stop(sfx_voice[index]);
8557 1725 }
8558
8559 // resumes a voice
8560 747 void resume_sfx(int32_t index)
8561 {
8562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
747 if (is_headless())
8563 747 return;
8564
8565 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8566 voice_start(sfx_voice[index]);
8567 747 }
8568
8569 // pauses all active voices
8570 452 void pause_all_sfx()
8571 {
8572
2/2
✓ Branch 0 taken 115712 times.
✓ Branch 1 taken 452 times.
116164 for(int32_t i=0; i<WAV_COUNT; i++)
8573
2/2
✓ Branch 0 taken 115711 times.
✓ Branch 1 taken 1 times.
115713 if(sfx_voice[i]!=-1)
8574 1 voice_stop(sfx_voice[i]);
8575 452 }
8576
8577 // resumes all paused voices
8578 438 void resume_all_sfx()
8579 {
8580
2/2
✓ Branch 0 taken 112128 times.
✓ Branch 1 taken 438 times.
112566 for(int32_t i=0; i<WAV_COUNT; i++)
8581
1/2
✓ Branch 0 taken 112128 times.
✗ Branch 1 not taken.
112128 if(sfx_voice[i]!=-1)
8582 voice_start(sfx_voice[i]);
8583 438 }
8584
8585 // stops an sfx and deallocates the voice
8586 7462663 void stop_sfx(int32_t index)
8587 {
8588
3/4
✓ Branch 0 taken 6277597 times.
✓ Branch 1 taken 1185066 times.
✓ Branch 2 taken 6277597 times.
✗ Branch 3 not taken.
7462663 if(index<=0 || index>=WAV_COUNT)
8589 1185066 return;
8590
8591
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6277585 times.
6277597 if(sfx_voice[index]!=-1)
8592 {
8593 12 deallocate_voice(sfx_voice[index]);
8594 12 sfx_voice[index]=-1;
8595 12 }
8596 7462663 }
8597
8598 // Stops SFX played by Hero's item of the given family
8599 128638 void stop_item_sfx(int32_t family)
8600 {
8601 128638 int32_t id=current_item_id(family);
8602
8603
2/2
✓ Branch 0 taken 128083 times.
✓ Branch 1 taken 555 times.
128638 if(id<0)
8604 128083 return;
8605
8606 555 stop_sfx(itemsbuf[id].usesound);
8607 128638 }
8608
8609 3223 void kill_sfx()
8610 {
8611
2/2
✓ Branch 0 taken 825088 times.
✓ Branch 1 taken 3223 times.
828311 for(int32_t i=0; i<WAV_COUNT; i++)
8612
2/2
✓ Branch 0 taken 825082 times.
✓ Branch 1 taken 6 times.
825094 if(sfx_voice[i]!=-1)
8613 {
8614 6 deallocate_voice(sfx_voice[i]);
8615 6 sfx_voice[i]=-1;
8616 6 }
8617 3223 }
8618
8619 659811 int32_t pan(int32_t x)
8620 {
8621
1/4
✓ Branch 0 taken 659811 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
659811 switch(pan_style)
8622 {
8623 case 0:
8624 return 128;
8625
8626 case 1:
8627 659811 return vbound((x>>1)+68,0,255);
8628
8629 case 2:
8630 return vbound(((x*3)>>2)+36,0,255);
8631 }
8632
8633 return vbound(x,0,255);
8634 659811 }
8635
8636 /*******************************/
8637 /******* Input Handlers ********/
8638 /*******************************/
8639
8640 25094006 bool joybtn(int32_t b)
8641 {
8642
1/2
✓ Branch 0 taken 25094006 times.
✗ Branch 1 not taken.
25094006 if(b == 0)
8643 return false;
8644
1/2
✓ Branch 0 taken 25094006 times.
✗ Branch 1 not taken.
25094006 if (b-1 >= joy[joystick_index].num_buttons)
8645 25094006 return false;
8646
8647 return joy[joystick_index].button[b-1].b !=0;
8648 25094006 }
8649
8650 bool joystick(int32_t s)
8651 {
8652 if(s < 0)
8653 return false;
8654 if (s >= joy[joystick_index].num_sticks)
8655 return false;
8656
8657 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8658 {
8659 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8660 return true;
8661 }
8662 return false;
8663 }
8664
8665 const char* joybtn_name(int32_t b)
8666 {
8667 if (b <= 0 || b > joy[joystick_index].num_buttons)
8668 return "";
8669
8670 return joy[joystick_index].button[b-1].name;
8671 }
8672
8673 const char* joystick_name(int32_t s)
8674 {
8675 if (s < 0 || s >= joy[joystick_index].num_sticks)
8676 return "";
8677
8678 return joy[joystick_index].stick[s].name;
8679 }
8680
8681 int32_t next_press_key();
8682
8683 int32_t next_joy_input(bool buttons)
8684 {
8685 clear_keybuf();
8686
8687 //first, we need to wait until they're pressing no buttons
8688 for(;;)
8689 {
8690 if(keypressed())
8691 {
8692 switch(readkey()>>8)
8693 {
8694 case KEY_ESC:
8695 return -1;
8696
8697 case KEY_SPACE:
8698 return 0;
8699 }
8700 }
8701
8702 poll_joystick();
8703 bool done = true;
8704
8705 if (buttons)
8706 {
8707 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8708 {
8709 if(joybtn(i)) done = false;
8710 }
8711 }
8712 else
8713 {
8714 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8715 {
8716 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8717 return -2;
8718 }
8719 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8720 {
8721 if(joystick(i)) done = false;
8722 }
8723 }
8724
8725 if(done) break;
8726 rest(1);
8727 }
8728
8729 //now, we need to wait for them to press any button
8730 for(;;)
8731 {
8732 if(keypressed())
8733 {
8734 switch(readkey()>>8)
8735 {
8736 case KEY_ESC:
8737 return -1;
8738
8739 case KEY_SPACE:
8740 return 0;
8741 }
8742 }
8743
8744 poll_joystick();
8745
8746 if (buttons)
8747 {
8748 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8749 {
8750 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8751 return -2;
8752 }
8753 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8754 {
8755 if(joybtn(i))
8756 return i;
8757 }
8758 }
8759 else
8760 {
8761 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8762 {
8763 if(joystick(i))
8764 return i;
8765 }
8766 }
8767 rest(1);
8768 }
8769 }
8770
8771 1209106 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8772 {
8773
2/2
✓ Branch 0 taken 1204755 times.
✓ Branch 1 taken 4351 times.
1209106 bool ret = btn && !flag;
8774 1209106 flag = rawbtn;
8775
8776 1209106 return ret;
8777 }
8778 190805710 static bool rButton(bool &btn, bool &flag)
8779 {
8780
2/2
✓ Branch 0 taken 183961269 times.
✓ Branch 1 taken 6844441 times.
190805710 bool ret = btn && !flag;
8781 190805710 flag = btn;
8782
8783 190805710 return ret;
8784 }
8785 2888985 static bool rButtonPeek(bool btn, bool flag)
8786 {
8787
2/2
✓ Branch 0 taken 2685887 times.
✓ Branch 1 taken 203098 times.
2888985 if(!btn)
8788 {
8789 2685887 return false;
8790 }
8791
2/2
✓ Branch 0 taken 17939 times.
✓ Branch 1 taken 185159 times.
203098 else if(!flag)
8792 {
8793 17939 return true;
8794 }
8795
8796 185159 return false;
8797 2888985 }
8798
8799 // Updated only by keyboard/gamepad.
8800 // If in replay mode, this is set directly by the replay system.
8801 // This should never be read from directly - use control_state instead.
8802 bool raw_control_state[ZC_CONTROL_STATES];
8803
8804 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8805 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8806 // lasts until the next call to load_control_state.
8807 bool control_state[ZC_CONTROL_STATES];
8808 bool disable_control[ZC_CONTROL_STATES];
8809 bool drunk_toggle_state[11];
8810 bool disabledKeys[127];
8811 bool KeyInput[127];
8812 bool KeyPress[127];
8813
8814 bool key_current_frame[127];
8815 bool key_previous_frame[127];
8816
8817 static bool key_system[127];
8818 static bool key_system_previous[127];
8819 static bool key_system_press[127];
8820
8821 bool button_press[ZC_CONTROL_STATES];
8822 bool button_hold[ZC_CONTROL_STATES];
8823
8824 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8825 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8826 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8827 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8828 #define STICK_PRECISION 56 //define your own sensitivity
8829
8830 7801176 void load_control_state()
8831 {
8832 7801176 load_control_called_this_frame = true;
8833
8834
2/2
✓ Branch 0 taken 4833663 times.
✓ Branch 1 taken 2967513 times.
7801176 if (replay_version_check(8, 11))
8835 {
8836
2/2
✓ Branch 0 taken 53415234 times.
✓ Branch 1 taken 2967513 times.
56382747 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8837 53415234 down_control_states[i] = raw_control_state[i];
8838 2967513 }
8839
8840
1/2
✓ Branch 0 taken 7801176 times.
✗ Branch 1 not taken.
7801176 if (!replay_is_replaying())
8841 {
8842 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8843 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8844 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8845 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8846 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8847 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8848 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8849 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8850 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8851 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8852 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8853 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8854 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8855 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8856
8857 if(num_joysticks != 0)
8858 {
8859 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8860 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8861 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8862 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8863 // zprint2("Detected %d joysticks... %d%d%d%d\n", num_joysticks, raw_control_state[14]?1:0, raw_control_state[15]?1:0, raw_control_state[16]?1:0, raw_control_state[17]?1:0);
8864 }
8865 else
8866 {
8867 raw_control_state[14] = false;
8868 raw_control_state[15] = false;
8869 raw_control_state[16] = false;
8870 raw_control_state[17] = false;
8871 // zprint2("Detected 0 joysticks... clearing inputaxis values.\n");
8872 }
8873 }
8874
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7801173 times.
7801176 if (replay_is_active())
8875 {
8876
2/2
✓ Branch 0 taken 1015215 times.
✓ Branch 1 taken 6785958 times.
7801173 if (replay_get_version() < 3)
8877 1015215 replay_poll();
8878
3/4
✓ Branch 0 taken 6785958 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5024583 times.
✓ Branch 3 taken 1761375 times.
6785958 else if (replay_is_replaying() && replay_get_version() < 6)
8879 1761375 replay_peek_input();
8880
3/4
✓ Branch 0 taken 5024583 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2057070 times.
✓ Branch 3 taken 2967513 times.
5024583 else if (replay_is_replaying() && replay_version_check(8, 11))
8881 2967513 replay_peek_input();
8882
2/2
✓ Branch 0 taken 6696883 times.
✓ Branch 1 taken 1104290 times.
7801173 if (replay_get_version() == 8)
8883 1104290 update_keys();
8884 7801173 }
8885
8886 // Some test replay files were made before a serious input bug was fixed, so instead
8887 // of re-doing them or tossing them out, just check for that zplay version.
8888
3/4
✓ Branch 0 taken 7801170 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 7679270 times.
7801176 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8889
2/2
✓ Branch 0 taken 140421060 times.
✓ Branch 1 taken 7801170 times.
148222230 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8890 {
8891 140421060 control_state[i] = raw_control_state[i];
8892
4/4
✓ Branch 0 taken 49487310 times.
✓ Branch 1 taken 90933750 times.
✓ Branch 2 taken 2410168 times.
✓ Branch 3 taken 47077142 times.
140421060 if (botched_input && !control_state[i])
8893 47077142 down_control_states[i] = false;
8894 140421060 }
8895 7801170 bool did_bad_cutscene_btn = false;
8896
2/2
✓ Branch 0 taken 7801170 times.
✓ Branch 1 taken 140421060 times.
148222230 for(int q = 0; q < 18; ++q)
8897
4/4
✓ Branch 0 taken 6465003 times.
✓ Branch 1 taken 133956057 times.
✓ Branch 2 taken 6464269 times.
✓ Branch 3 taken 734 times.
140421794 if(control_state[q] && !active_cutscene.can_button(q))
8898 {
8899 734 control_state[q] = false;
8900 734 did_bad_cutscene_btn = true;
8901 734 }
8902
2/2
✓ Branch 0 taken 7800655 times.
✓ Branch 1 taken 515 times.
7801170 if(did_bad_cutscene_btn)
8903 515 active_cutscene.error();
8904
8905 7801170 button_press[0]=rButton(control_state[0],button_hold[0]);
8906 7801170 button_press[1]=rButton(control_state[1],button_hold[1]);
8907 7801170 button_press[2]=rButton(control_state[2],button_hold[2]);
8908 7801170 button_press[3]=rButton(control_state[3],button_hold[3]);
8909 7801170 button_press[4]=rButton(control_state[4],button_hold[4]);
8910 7801170 button_press[5]=rButton(control_state[5],button_hold[5]);
8911 7801170 button_press[6]=rButton(control_state[6],button_hold[6]);
8912 7801170 button_press[7]=rButton(control_state[7],button_hold[7]);
8913 7801170 button_press[8]=rButton(control_state[8],button_hold[8]);
8914 7801170 button_press[9]=rButton(control_state[9],button_hold[9]);
8915 7801170 button_press[10]=rButton(control_state[10],button_hold[10]);
8916 7801170 button_press[11]=rButton(control_state[11],button_hold[11]);
8917 7801170 button_press[12]=rButton(control_state[12],button_hold[12]);
8918 7801170 button_press[13]=rButton(control_state[13],button_hold[13]);
8919 7801170 button_press[14]=rButton(control_state[14],button_hold[14]);
8920 7801170 button_press[15]=rButton(control_state[15],button_hold[15]);
8921 7801170 button_press[16]=rButton(control_state[16],button_hold[16]);
8922 7801170 button_press[17]=rButton(control_state[17],button_hold[17]);
8923 7801170 }
8924
8925 // Returns true if any game key is pressed. This is needed because keypressed()
8926 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8927 40250637 bool zc_key_pressed()
8928 //may also need to use zc_getrawkey
8929 {
8930
7/10
✓ Branch 0 taken 32597771 times.
✓ Branch 1 taken 7652866 times.
✓ Branch 2 taken 7652866 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7652866 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6396392 times.
✓ Branch 7 taken 6396392 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2461754 times.
42712391 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8931
4/6
✓ Branch 0 taken 6396392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6396392 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4844168 times.
✓ Branch 5 taken 4844168 times.
6396392 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8932
4/6
✓ Branch 0 taken 4844168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4844168 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3143220 times.
✓ Branch 5 taken 3143220 times.
4844168 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8933
4/6
✓ Branch 0 taken 3143220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3143220 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2732278 times.
✓ Branch 5 taken 2732278 times.
3143220 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8934
1/2
✓ Branch 0 taken 2732278 times.
✗ Branch 1 not taken.
2732278 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8935
3/4
✓ Branch 0 taken 2612871 times.
✓ Branch 1 taken 119407 times.
✓ Branch 2 taken 2612871 times.
✗ Branch 3 not taken.
2732278 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8936
3/4
✓ Branch 0 taken 2493968 times.
✓ Branch 1 taken 118903 times.
✓ Branch 2 taken 2493968 times.
✗ Branch 3 not taken.
2612871 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8937
3/4
✓ Branch 0 taken 2478823 times.
✓ Branch 1 taken 15145 times.
✓ Branch 2 taken 2478823 times.
✗ Branch 3 not taken.
2493968 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8938
3/4
✓ Branch 0 taken 2465324 times.
✓ Branch 1 taken 13499 times.
✓ Branch 2 taken 2465324 times.
✗ Branch 3 not taken.
2478823 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8939
3/4
✓ Branch 0 taken 2462830 times.
✓ Branch 1 taken 2494 times.
✓ Branch 2 taken 2462830 times.
✗ Branch 3 not taken.
2465324 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8940
3/4
✓ Branch 0 taken 2462612 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 2462612 times.
✗ Branch 3 not taken.
2462830 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8941
3/4
✓ Branch 0 taken 2461773 times.
✓ Branch 1 taken 839 times.
✓ Branch 2 taken 2461773 times.
✗ Branch 3 not taken.
2462612 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8942
2/4
✓ Branch 0 taken 2461773 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461773 times.
✗ Branch 3 not taken.
2461773 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8943
2/2
✓ Branch 0 taken 2461754 times.
✓ Branch 1 taken 19 times.
2461773 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8944 72020999 return true;
8945
8946 2461754 return false;
8947 9287211 }
8948
8949 149956017 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8950 {
8951 149956017 bool ret = false, drunkstate = false, rawret = false;;
8952 149956017 bool* flag = &down_control_states[btn];
8953
2/7
✓ Branch 0 taken 140659469 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 9296548 times.
149956017 switch(btn)
8954 {
8955 case btnF12:
8956 ret = zc_getkey(KEY_F12, ignoreDisable);
8957 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8958 eatEntirely = false;
8959 break;
8960 case btnF11:
8961 ret = zc_getkey(KEY_F11, ignoreDisable);
8962 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8963 eatEntirely = false;
8964 break;
8965 case btnF5:
8966 ret = zc_getkey(KEY_F5, ignoreDisable);
8967 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8968 eatEntirely = false;
8969 break;
8970 case btnQ:
8971 ret = zc_getkey(KEY_Q, ignoreDisable);
8972 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8973 eatEntirely = false;
8974 break;
8975 case btnI:
8976 ret = zc_getkey(KEY_I, ignoreDisable);
8977 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8978 eatEntirely = false;
8979 break;
8980 case btnM:
8981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9296548 times.
9296548 if(FFCore.kb_typing_mode) return false;
8982 9296548 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8983 9296548 eatEntirely = false;
8984 9296548 break;
8985 default: //control_state[] index
8986
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 140659469 times.
140659469 if(FFCore.kb_typing_mode) return false;
8987
5/6
✓ Branch 0 taken 139859690 times.
✓ Branch 1 taken 799779 times.
✓ Branch 2 taken 2237468 times.
✓ Branch 3 taken 137622222 times.
✓ Branch 4 taken 2237468 times.
✗ Branch 5 not taken.
140659469 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8988
2/2
✓ Branch 0 taken 8036378 times.
✓ Branch 1 taken 132623091 times.
140659469 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8989
4/4
✓ Branch 0 taken 126521127 times.
✓ Branch 1 taken 14138342 times.
✓ Branch 2 taken 3004 times.
✓ Branch 3 taken 14135338 times.
154797811 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8990 140659469 rawret = raw_control_state[btn];
8991 140659469 }
8992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149956017 times.
149956017 assert(flag);
8993
2/2
✓ Branch 0 taken 95473276 times.
✓ Branch 1 taken 54482741 times.
149956017 if(press)
8994 {
8995
2/2
✓ Branch 0 taken 2888985 times.
✓ Branch 1 taken 51593756 times.
54482741 if(peek)
8996 2888985 ret = rButtonPeek(ret, *flag);
8997
2/2
✓ Branch 0 taken 50384650 times.
✓ Branch 1 taken 1209106 times.
51593756 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8998 1209106 else ret = rButton(ret, *flag, rawret);
8999 54482741 }
9000
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 149956017 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
149956017 if(eatEntirely && ret) control_state[btn] = false;
9001
3/4
✓ Branch 0 taken 112376241 times.
✓ Branch 1 taken 37579776 times.
✓ Branch 2 taken 112376241 times.
✗ Branch 3 not taken.
149956017 if(drunk && drunkstate) ret = !ret;
9002 149956017 return ret;
9003 149956017 }
9004
9005 7465295 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
9006 {
9007 7465295 byte ret = 0;
9008
2/2
✓ Branch 0 taken 5485975 times.
✓ Branch 1 taken 1979320 times.
7465295 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
9009
2/2
✓ Branch 0 taken 7334481 times.
✓ Branch 1 taken 130814 times.
7465295 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
9010
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
9011
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
9012
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
9013
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
9014
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
9015
2/2
✓ Branch 0 taken 7334606 times.
✓ Branch 1 taken 130689 times.
7465295 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
9016 7465295 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
9017 }
9018
9019 1114 byte checkIntBtnVal(byte intbtn, byte vals)
9020 {
9021 1114 return intbtn&vals;
9022 }
9023
9024 1767437 bool Up()
9025 {
9026 1767437 return getInput(btnUp);
9027 }
9028 147234 bool Down()
9029 {
9030 147234 return getInput(btnDown);
9031 }
9032 257723 bool Left()
9033 {
9034 257723 return getInput(btnLeft);
9035 }
9036 286925 bool Right()
9037 {
9038 286925 return getInput(btnRight);
9039 }
9040 164908 bool cAbtn()
9041 {
9042 164908 return getInput(btnA);
9043 }
9044 1411891 bool cBbtn()
9045 {
9046 1411891 return getInput(btnB);
9047 }
9048 bool cSbtn()
9049 {
9050 return getInput(btnS);
9051 }
9052 68744 bool cLbtn()
9053 {
9054 68744 return getInput(btnL);
9055 }
9056 68744 bool cRbtn()
9057 {
9058 68744 return getInput(btnR);
9059 }
9060 bool cPbtn()
9061 {
9062 return getInput(btnP);
9063 }
9064 bool cEx1btn()
9065 {
9066 return getInput(btnEx1);
9067 }
9068 bool cEx2btn()
9069 {
9070 return getInput(btnEx2);
9071 }
9072 bool cEx3btn()
9073 {
9074 return getInput(btnEx3);
9075 }
9076 bool cEx4btn()
9077 {
9078 return getInput(btnEx4);
9079 }
9080 bool AxisUp()
9081 {
9082 return getInput(btnAxisUp);
9083 }
9084 bool AxisDown()
9085 {
9086 return getInput(btnAxisDown);
9087 }
9088 bool AxisLeft()
9089 {
9090 return getInput(btnAxisLeft);
9091 }
9092 bool AxisRight()
9093 {
9094 return getInput(btnAxisRight);
9095 }
9096
9097 bool cMbtn()
9098 {
9099 return getInput(btnM);
9100 }
9101 bool cF12()
9102 {
9103 return getInput(btnF12);
9104 }
9105 bool cF11()
9106 {
9107 return getInput(btnF11);
9108 }
9109 bool cF5()
9110 {
9111 return getInput(btnF5);
9112 }
9113 bool cQ()
9114 {
9115 return getInput(btnQ);
9116 }
9117 bool cI()
9118 {
9119 return getInput(btnI);
9120 }
9121
9122 130270 bool rUp()
9123 {
9124 130270 return getInput(btnUp, true);
9125 }
9126 130174 bool rDown()
9127 {
9128 130174 return getInput(btnDown, true);
9129 }
9130 130122 bool rLeft()
9131 {
9132 130122 return getInput(btnLeft, true);
9133 }
9134 129657 bool rRight()
9135 {
9136 129657 return getInput(btnRight, true);
9137 }
9138 1296 bool rAbtn()
9139 {
9140 1296 return getInput(btnA, true);
9141 }
9142 1296 bool rBbtn()
9143 {
9144 1296 return getInput(btnB, true);
9145 }
9146 7397110 bool rSbtn()
9147 {
9148 7397110 return getInput(btnS, true);
9149 }
9150 9287211 bool rMbtn()
9151 {
9152 9287211 return getInput(btnM, true);
9153 }
9154 129441 bool rLbtn()
9155 {
9156 129441 return getInput(btnL, true);
9157 }
9158 129436 bool rRbtn()
9159 {
9160 129436 return getInput(btnR, true);
9161 }
9162 7333574 bool rPbtn()
9163 {
9164 7333574 return getInput(btnP, true);
9165 }
9166 bool rEx1btn()
9167 {
9168 return getInput(btnEx1, true);
9169 }
9170 bool rEx2btn()
9171 {
9172 return getInput(btnEx2, true);
9173 }
9174 140087 bool rEx3btn()
9175 {
9176 140087 return getInput(btnEx3, true);
9177 }
9178 140087 bool rEx4btn()
9179 {
9180 140087 return getInput(btnEx4, true);
9181 }
9182 bool rAxisUp()
9183 {
9184 return getInput(btnAxisUp, true);
9185 }
9186 bool rAxisDown()
9187 {
9188 return getInput(btnAxisDown, true);
9189 }
9190 bool rAxisLeft()
9191 {
9192 return getInput(btnAxisLeft, true);
9193 }
9194 bool rAxisRight()
9195 {
9196 return getInput(btnAxisRight, true);
9197 }
9198
9199 bool rF11()
9200 {
9201 return getInput(btnF11, true);
9202 }
9203 bool rQ()
9204 {
9205 return getInput(btnQ, true);
9206 }
9207 bool rI()
9208 {
9209 return getInput(btnI, true);
9210 }
9211
9212 18227830 bool DrunkUp()
9213 {
9214 18227830 return getInput(btnUp, false, true);
9215 }
9216 16890614 bool DrunkDown()
9217 {
9218 16890614 return getInput(btnDown, false, true);
9219 }
9220 10289030 bool DrunkLeft()
9221 {
9222 10289030 return getInput(btnLeft, false, true);
9223 }
9224 8834523 bool DrunkRight()
9225 {
9226 8834523 return getInput(btnRight, false, true);
9227 }
9228 8036020 bool DrunkcAbtn()
9229 {
9230 8036020 return getInput(btnA, false, true);
9231 }
9232 8017468 bool DrunkcBbtn()
9233 {
9234 8017468 return getInput(btnB, false, true);
9235 }
9236 7264444 bool DrunkcEx1btn()
9237 {
9238 7264444 return getInput(btnEx1, false, true);
9239 }
9240 7264464 bool DrunkcEx2btn()
9241 {
9242 7264464 return getInput(btnEx2, false, true);
9243 }
9244 bool DrunkcSbtn()
9245 {
9246 return getInput(btnS, false, true);
9247 }
9248 bool DrunkcMbtn()
9249 {
9250 return getInput(btnM, false, true);
9251 }
9252 bool DrunkcLbtn()
9253 {
9254 return getInput(btnL, false, true);
9255 }
9256 bool DrunkcRbtn()
9257 {
9258 return getInput(btnR, false, true);
9259 }
9260 bool DrunkcPbtn()
9261 {
9262 return getInput(btnP, false, true);
9263 }
9264
9265 bool DrunkrUp()
9266 {
9267 return getInput(btnUp, true, true);
9268 }
9269 bool DrunkrDown()
9270 {
9271 return getInput(btnDown, true, true);
9272 }
9273 bool DrunkrLeft()
9274 {
9275 return getInput(btnLeft, true, true);
9276 }
9277 bool DrunkrRight()
9278 {
9279 return getInput(btnRight, true, true);
9280 }
9281 6082228 bool DrunkrAbtn()
9282 {
9283 6082228 return getInput(btnA, true, true);
9284 }
9285 6099060 bool DrunkrBbtn()
9286 {
9287 6099060 return getInput(btnB, true, true);
9288 }
9289 71669 bool DrunkrEx1btn()
9290 {
9291 71669 return getInput(btnEx1, true, true);
9292 }
9293 71662 bool DrunkrEx2btn()
9294 {
9295 71662 return getInput(btnEx2, true, true);
9296 }
9297 bool DrunkrEx3btn()
9298 {
9299 return getInput(btnEx3, true, true);
9300 }
9301 bool DrunkrEx4btn()
9302 {
9303 return getInput(btnEx4, true, true);
9304 }
9305 bool DrunkrSbtn()
9306 {
9307 return getInput(btnS, true, true);
9308 }
9309 bool DrunkrMbtn()
9310 {
9311 return getInput(btnM, true, true);
9312 }
9313 6689226 bool DrunkrLbtn()
9314 {
9315 6689226 return getInput(btnL, true, true);
9316 }
9317 6685751 bool DrunkrRbtn()
9318 {
9319 6685751 return getInput(btnR, true, true);
9320 }
9321 bool DrunkrPbtn()
9322 {
9323 return getInput(btnP, true, true);
9324 }
9325
9326 9337 void eat_buttons()
9327 {
9328 9337 getInput(btnA, true, false, true);
9329 9337 getInput(btnB, true, false, true);
9330 9337 getInput(btnS, true, false, true);
9331 9337 getInput(btnM, true, false, true);
9332 9337 getInput(btnL, true, false, true);
9333 9337 getInput(btnR, true, false, true);
9334 9337 getInput(btnP, true, false, true);
9335 9337 getInput(btnEx1, true, false, true);
9336 9337 getInput(btnEx2, true, false, true);
9337 9337 getInput(btnEx3, true, false, true);
9338 9337 getInput(btnEx4, true, false, true);
9339 9337 }
9340
9341 // Is true for the _first frame_ of a key press.
9342 // But! it is possible that a script manually sets the value of KeyPress,
9343 // in which case it will be restored to the "true" value based on `key_current_frame`
9344 // and `key_previous_frame` on the next frame.
9345 14 bool zc_readkey(int32_t k, bool ignoreDisable)
9346 {
9347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(ignoreDisable) return KeyPress[k];
9348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 switch(k)
9349 {
9350 case KEY_F7:
9351 case KEY_F8:
9352 case KEY_F9:
9353 return KeyPress[k];
9354
9355 default:
9356
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 return KeyPress[k] && !disabledKeys[k];
9357 }
9358 14 }
9359
9360 // Is true for _every frame_ a key is held down.
9361 // But! it is possible that a script manually sets the value of KeyInput,
9362 // in which case it will be restored to the "true" value based on `key_current_frame`
9363 // on the next frame.
9364 bool zc_getkey(int32_t k, bool ignoreDisable)
9365 {
9366 if(ignoreDisable) return KeyInput[k];
9367 switch(k)
9368 {
9369 case KEY_F7:
9370 case KEY_F8:
9371 case KEY_F9:
9372 return KeyInput[k];
9373
9374 default:
9375 return KeyInput[k] && !disabledKeys[k];
9376 }
9377 }
9378
9379 // Reads (and then clears) the current frame key state directly.
9380 // Scripts can also modify `key_current_frame`.
9381 303 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9382 {
9383
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 301 times.
303 if(zc_getrawkey(k, ignoreDisable))
9384 {
9385 2 _key[k]=key[k]=key_current_frame[k]=0;
9386 2 return true;
9387 }
9388 301 _key[k]=key[k]=key_current_frame[k]=0;
9389 301 return false;
9390 303 }
9391
9392 // Reads the current frame key state directly.
9393 // Scripts can also modify `key_current_frame`.
9394 63252960 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9395 {
9396
2/2
✓ Branch 0 taken 53965721 times.
✓ Branch 1 taken 9287239 times.
63252960 if(ignoreDisable) return key_current_frame[k];
9397
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287239 times.
9287239 switch(k)
9398 {
9399 case KEY_F7:
9400 case KEY_F8:
9401 case KEY_F9:
9402 return key_current_frame[k];
9403
9404 default:
9405
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9287239 times.
9287239 return key_current_frame[k] && !disabledKeys[k];
9406 }
9407 63252960 }
9408
9409 // Only used for a handful of keys, like tilde and Function keys.
9410 // This state is never read within the game.
9411 // It exists so that all keyboard input still functions during replay,
9412 // without inadvertently doing things like toggling throttling if the player
9413 // presses ~
9414 9287211 bool zc_get_system_key(int32_t k)
9415 {
9416 9287211 return key_system[k];
9417 }
9418
9419 // True for the _first_ frame of a key press.
9420 83584899 bool zc_read_system_key(int32_t k)
9421 {
9422 83584899 return key_system_press[k];
9423 }
9424
9425 1179475797 bool is_system_key(int32_t k)
9426 {
9427
2/2
✓ Branch 0 taken 1095890898 times.
✓ Branch 1 taken 83584899 times.
1179475797 switch (k)
9428 {
9429 case KEY_BACKQUOTE:
9430 case KEY_CLOSEBRACE:
9431 case KEY_END:
9432 case KEY_HOME:
9433 case KEY_OPENBRACE:
9434 case KEY_PGDN:
9435 case KEY_PGUP:
9436 case KEY_TAB:
9437 case KEY_TILDE:
9438 83584899 return true;
9439 }
9440 1095890898 return is_Fkey(k);
9441 1179475797 }
9442
9443 9287211 void update_system_keys()
9444 {
9445
2/2
✓ Branch 0 taken 1179475797 times.
✓ Branch 1 taken 9287211 times.
1188763008 for (int32_t q = 0; q < 127; ++q)
9446 {
9447
2/2
✓ Branch 0 taken 195031431 times.
✓ Branch 1 taken 984444366 times.
1179475797 if (!is_system_key(q))
9448 984444366 continue;
9449
9450 195031431 key_system[q] = key[q];
9451
1/2
✓ Branch 0 taken 195031431 times.
✗ Branch 1 not taken.
195031431 key_system_press[q] = key_system[q] && !key_system_previous[q];
9452 195031431 key_system_previous[q] = key_system[q];
9453 195031431 }
9454 9287211 }
9455
9456 10391501 void update_keys()
9457 {
9458
2/2
✓ Branch 0 taken 1319720627 times.
✓ Branch 1 taken 10391501 times.
1330112128 for (int32_t q = 0; q < 127; ++q)
9459 {
9460 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9461
1/2
✓ Branch 0 taken 1319720627 times.
✗ Branch 1 not taken.
1319720627 if (!replay_is_replaying())
9462 key_current_frame[q] = key[q];
9463
9464
2/2
✓ Branch 0 taken 1309932100 times.
✓ Branch 1 taken 9788527 times.
1319720627 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9465 1319720627 KeyInput[q] = key_current_frame[q];
9466 1319720627 key_previous_frame[q] = key_current_frame[q];
9467 1319720627 }
9468 10391501 }
9469
9470 bool zc_disablekey(int32_t k, bool val)
9471 {
9472 switch(k)
9473 {
9474 case KEY_F7:
9475 case KEY_F8:
9476 case KEY_F9:
9477 return false;
9478
9479 default:
9480 disabledKeys[k] = val;
9481 return true;
9482 }
9483 }
9484
9485 void zc_putpixel(int32_t layer, int32_t x, int32_t y, int32_t cset, int32_t color, int32_t timer)
9486 {
9487 timer=timer;
9488 particles.add(new particle(zfix(x), zfix(y), layer, cset, color));
9489 }
9490